0

I'm trying to install ripgrep in emacs in order to use it with hledger-mode

I added this lines to my ~/.emacs.d/init.el:

(require 'rg)
(rg-enable-default-bindings)

And running emacs -nw --debug-init shows me this:

Debugger entered--Lisp error: (file-missing "Cannot open load file" "No such file or directory" "rg")

this is my brew info rg

==> ripgrep: stable 13.0.0 (bottled), HEAD
Search tool like grep and The Silver Searcher
https://github.com/BurntSushi/ripgrep
/opt/homebrew/Cellar/ripgrep/13.0.0 (13 files, 5.8MB) *
  Poured from bottle on 2023-01-18 at 19:36:26
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/ripgrep.rb
License: Unlicense
==> Dependencies
Build: asciidoctor, pkg-config, rust
Required: pcre2
==> Options
--HEAD
    Install HEAD version
==> Caveats
zsh completions have been installed to:
  /opt/homebrew/share/zsh/site-functions
==> Analytics
install: 9,411 (30 days), 30,297 (90 days), 122,177 (365 days)
install-on-request: 9,241 (30 days), 29,736 (90 days), 118,865 (365 days)
build-error: 3 (30 days)

and emacs --version

GNU Emacs 28.2
Copyright (C) 2022 Free Software Foundation, Inc.
GNU Emacs comes with ABSOLUTELY NO WARRANTY.
You may redistribute copies of GNU Emacs
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING.

running C-u M-: (getenv "PATH") inside emacs show me /opt/homebrew/bin in the PATH and ls -l /opt/homebrew/bin/rg shows the following:

lrwxr-xr-x 1 XXXX XXXX 31 Jan 18 19:36 rg -> ../Cellar/ripgrep/13.0.0/bin/rg

I have and iMac M1 2001 with ventura 13.1 and Rosetta installed.

Here is my entire ~/.emacs.d/init.el:

;; Install MELPA

(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
;; Comment/uncomment this line to enable MELPA Stable if desired.  See `package-archive-priorities`
;; and `package-pinned-packages`. Most users will not need or want to do this.
;;(add-to-list 'package-archives '("melpa-stable" . "https://stable.melpa.org/packages/") t)
(package-initialize)

(add-hook 'after-init-hook 'global-company-mode)

(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(package-selected-packages '(hledger-mode)))

(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 )

;; load mu4e from the installation path.
;; yours might differ check with the Emacs installation
(add-to-list 'load-path "/opt/homebrew/Cellar/mu/1.8.13/share/emacs/site-lisp/mu/mu4e")
(require 'mu4e)

;; the headers to show in the headers list -- a pair of a field
;; and its width, with `nil' meaning 'unlimited'
;; (better only use that for the last field.
;; These are the defaults:
(setq mu4e-headers-fields
    '( (:human-date    .  25)    ;; alternatively, use :human-date
       (:flags         .   6)
       (:maildir       .  20)
       (:from-or-to    .  22)
       (:subject       .  nil))) ;; alternatively, use :thread-subject%:

;;(Use-package mu4e
;;  :load-path  "/usr/local/share/emacs/site-lisp/mu/mu4e/")
;;  :load-path "/opt/homebrew/Cellar/mu/1.8.13/bin")

;; for sending mails
(require 'smtpmail)

;; we installed this with homebrew
(setq mu4e-mu-binary (executable-find "mu"))

;; this is the directory we created before:
(setq mu4e-maildir "~/.maildir")

;; this command is called to sync imap servers:
(setq mu4e-get-mail-command (concat (executable-find "mbsync") " -a"))
;; how often to call it in seconds:
(setq mu4e-update-interval 300)

;; save attachment to desktop by default
;; or another choice of yours:
(setq mu4e-attachment-dir "~/Downloads")

;; rename files when moving - needed for mbsync:
(setq mu4e-change-filenames-when-moving t)

;; list of your email adresses:
(setq mu4e-user-mail-address-list '("justme@gmail.com"))

(when (memq window-system '(mac ns x))
  (exec-path-from-shell-initialize))

;; check your ~/.maildir to see how the subdirectories are called
;; for the generic imap account:
;; e.g `ls ~/.maildir/example'
(setq   mu4e-maildir-shortcuts
        '(("/gmail/INBOX" . ?g)
      (:maildir "/gmail/Archives" :key ?a)
          ("/gmail/[Gmail]/Enviados" . ?G)))

;;(add-to-list 'mu4e-bookmarks
;;             (make-mu4e-bookmark
;;              :name "Inbox - Gmail"
;;              :query "maildir:/gmail/INBOX"
;;              :key ?g))

(setq mu4e-contexts
       `(,(make-mu4e-context
          :name "gmail"
          :enter-func
          (lambda () (mu4e-message "Enter justme@gmail.com context"))
          :leave-func
          (lambda () (mu4e-message "Leave justme@gmail.com context"))
          :match-func
          (lambda (msg)
            (when msg
              (mu4e-message-contact-field-matches msg
                                                  :to "afrancocorrea@gmail.com")))
          :vars '((user-mail-address . "justme@gmail.com")
                  (user-full-name . "Me and myself")
                  (mu4e-drafts-folder . "/gmail/Borradores")
                  (mu4e-refile-folder . "/gmail/Archives")
                  (mu4e-sent-folder . "/gmail/Enviados")
                  (mu4e-trash-folder . "/gmail/Papelera")))))

;; gpg encryptiom & decryption:
;; this can be left alone
;;(require 'epa-file)
;;(epa-file-enable)
;;(setq epa-pinentry-mode 'loopback)
;;(auth-source-forget-all-cached)

;; don't keep message compose buffers around after sending:
(setq message-kill-buffer-on-exit t)

;; send function:
(setq send-mail-function 'sendmail-send-it
      message-send-mail-function 'sendmail-send-it)

;; send program:
;; this is exeranal. remember we installed it before.
(setq sendmail-program (executable-find "msmtp"))

;; select the right sender email from the context.
(setq message-sendmail-envelope-from 'header)

;; chose from account before sending
;; this is a custom function that works for me.
;; well I stole it somewhere long ago.
;; I suggest using it to make matters easy
;; of course adjust the email adresses and account descriptions
(defun timu/set-msmtp-account ()
  (if (message-mail-p)
      (save-excursion
        (let*
            ((from (save-restriction
                     (message-narrow-to-headers)
                     (message-fetch-field "from")))
             (account
              (cond
               ((string-match "justme@gmail.com" from) "gmail"))))
          (setq message-sendmail-extra-arguments (list '"-a" account))))))

(add-hook 'message-send-mail-hook 'timu/set-msmtp-account)

;; mu4e cc & bcc
;; this is custom as well
(add-hook 'mu4e-compose-mode-hook
          (defun timu/add-cc-and-bcc ()
            "My Function to automatically add Cc & Bcc: headers.
    This is in the mu4e compose mode."
            (save-excursion (message-add-header "Cc:\n"))
            (save-excursion (message-add-header "Bcc:\n"))))

;; mu4e address completion
(add-hook 'mu4e-compose-mode-hook 'company-mode)

;; store link to message if in header view, not to header query:
(setq org-mu4e-link-query-in-headers-mode nil)
;; don't have to confirm when quitting:
(setq mu4e-confirm-quit nil)
;; number of visible headers in horizontal split view:
(setq mu4e-headers-visible-lines 20)
;; don't show threading by default:
(setq mu4e-headers-show-threads nil)
;; hide annoying "mu4e Retrieving mail..." msg in mini buffer:
(setq mu4e-hide-index-messages t)
;; customize the reply-quote-string:
(setq message-citation-line-format "%N @ %Y-%m-%d %H:%M :\n")
;; M-x find-function RET message-citation-line-format for docs:
(setq message-citation-line-function 'message-insert-formatted-citation-line)
;; by default do not show related emails:
(setq mu4e-headers-include-related nil)
;; by default do not show threads:
(setq mu4e-headers-show-threads nil)

(require 'rg)
(rg-enable-default-bindings)

;;; Basic configuration
(require 'hledger-mode)

;; To open files with .journal extension in hledger-mode
(add-to-list 'auto-mode-alist '("\\.journal\\'" . hledger-mode))

;; Personal Accounting
(global-set-key (kbd "C-c e") 'hledger-jentry)
(global-set-key (kbd "C-c j") 'hledger-run-command)

;; Provide the path to you journal file.
;; The default location is too opinionated.
(setq hledger-jfile "~/Documents/hledger/hledger.journal")

  • Can you show your full init.el file and what's in the .emacs.d/ folder ? I'm guessing you installed ripgrep on your Mac but you don't have rg.el in your .emacs.d/ folder – Thibault Cimic Jan 21 '23 at 12:10
  • Thanks for answer, I just added my `init.el` to the question, and you're right I don't have an rg.el in my `~/.emacs.d` folder. – Andres Franco Jan 21 '23 at 12:57

1 Answers1

0

When installing ripgrep with brew, you're making it available for your computer on the command line, ie the terminal. It doesn't mean you told Emacs how to use it. For that you have to follow installation instruction from here.

The easiest solution would be to mimic the way it is done in your init.el for mu4e, ie :

1). download rg.el from the GitHub link of the installation instruction above

2). Place the file somewhere in your .emacs.d/ folder

3). Add the path to the rg.el file the same way it is done in your init.el for mu4e and the require 'rg

Doing this should fix your problem, but for a better understanding of Emacs configuration I recommend you look at System crafter's YouTube channel

Thibault Cimic
  • 320
  • 1
  • 9
  • Thanks for your answer, I followed your steps, but I get the same message, I also checked for running rg in shell in order to verify the PATH and I could run it there. I think emacs is not finding rg executable then I tried `(add-to-list 'load-path "/opt/homebrew/Cellar/ripgrep/13.0.0/bin") (require 'rg) ` without success – Andres Franco Jan 22 '23 at 15:37
  • It's done with M-x package-install RET rg.... but I don't understand yet why didn't worked before or why have I to install rg via brew too. – Andres Franco Jan 22 '23 at 19:34
  • What's the initial path you gave to the add-to-list function in the init.el file ? Did you remove the .el at the end ? Like for mu4e ? – Thibault Cimic Jan 22 '23 at 19:52
  • It's `(add-to-list 'load-path "/opt/homebrew/Cellar/ripgrep/13.0.0/bin")`, this is the location of the rg executable, also there is a symlink in /opt/homebrew/bin that is the route included in the system PATH – Andres Franco Jan 23 '23 at 02:53
  • @AndresFranco What you installed via M-x package-install is the Emacs package for dealing with rg (https://github.com/dajva/rg.el). Like quite a few other packages this shells out to an executable that needs to be installed in your system (the rg binary installed via Homebrew). (require 'rg) loads the Elisp files of the rg package, it has nothing to do with the binary (except for certain functions/commands in the Elisp shelling out to the rg binary). – Michael Kohl Jan 24 '23 at 09:36