By default the modeline likeļ¼
Emacs displays Git-master when I am working in a directory that is under the Git version control system.Now I customize modeline in the file init-modeline.el like this:
(setq-default mode-line-format
(list
;; the buffer name; the file name as a tool tip
'(:eval (propertize "%b " 'face font-lock-keyword-face
'help-echo (buffer-file-name)))
;; line and column
"("
"%02l" "," "%01c"
") "
......
))
Then add (require 'init-modeline) to init.el.
Now emacs does not display git branch in the emacs modeline, so I add '(vc-mode vc-mode) to init-modeline.el like this:
(setq-default mode-line-format
(list
;; the buffer name; the file name as a tool tip
'(:eval (propertize "%b " 'face font-lock-keyword-face
'help-echo (buffer-file-name)))
;; line and column
"("
"%02l" "," "%01c"
") "
'(vc-mode vc-mode)
......
))
Now modeline shows like this:
It only shows -master.How can I show Git-master?
The value of variable vc-mode in init-mode buffer like:
vc-mode's value is #(" :master" 0 1
(face sml/vc-edited)
1 8
(help-echo "Locally modified file under the Git version control system\nCurrent revision: master\nmouse-1: Version Control menu" face sml/vc-edited local-map
(keymap
(mode-line keymap
(down-mouse-1 menu-item "Version Control" vc-menu-map :filter vc-menu-map-filter)))
mouse-face mode-line-highlight))
Local in buffer init.el; global value is nil
Automatically becomes permanently buffer-local when set.
This variable may be risky if used as a file-local variable.
Related
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")
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
My requirement is to delete file based on it displayed. Following is code snippet where I listed files but when I select option it displays file and when I capture file name its not happening only getting key not VALUE($REPLY only displays key but not value). Can someone help me out.
#!/bin/bash
select list in $(ls *.tmp)
do
echo $list
echo Do you want to delete files ?
read userInput
echo "UserInput is :: " $userInput
echo "Reply is :: " $REPLY
if [ $userInput == $REPLY ] ; then
# rm $REPLY
echo 'Yes'
break
done
----OUTPUT-----
1) +~JF1905393034413613060.tmp
2) +~JF2032005334435574091.tmp
3) +~JF3116454937363220082.tmp
4) +~JF3334986634800781310.tmp
5) +~JF3651229840772890748.tmp
6) +~JF3882306323060007639.tmp
7) +~JF573641658479505435.tmp
8) +~JF6137053351660236007.tmp
9) +~JF6277682393160684532.tmp
10) +~JF6385610668752278364.tmp
11) +~JF6824954027739238354.tmp
12) +~JF7876557427734797684.tmp
#? 4
+~JF3334986634800781310.tmp
Do you want to delete files ?
y
UserInput is :: y
Reply is :: 4
No
Try this:
PS3="Pick a file number to delete (or Ctrl-C to quit): "
select f in *.tmp ; do echo rm "$f" ; done
Then remove the echo to make it actually delete files.
Hey guys I need to see my ruby version and gemset name in emacs mode-line. Do you know how to do it?
Take a look at rvm.el. I provides many features that make the use of RVM from Emacs more enjoyable.
I tried but I can't custom strings to mode-line so I customize all of it.
;; modeline
(defun branch-name ()
(when vc-mode
(concat "\ue0a0 " (substring vc-mode 5))
))
(defun current-ruby ()
(when vc-mode
(replace-regexp-in-string "\n$" "" (shell-command-to-string "~/.rvm/bin/rvm-prompt"))
))
(setq-default mode-line-format
(list
"[" mode-line-modified "]"
" "
"%b"
" | "
'mode-name
" | "
'(:eval (projectile-project-name))
" "
'(:eval (branch-name))
" | "
'(:eval (current-ruby))
" | "
"%p (%l,%c)"
))
I call git get the toplevel dir (according to
Is there a way to get the git root directory in one command?
).
(let ((tmpbuffer (get-buffer-create (make-temp-name "git"))))
(call-process "git" nil tmpbuffer nil "rev-parse" "--show-toplevel")
(with-current-buffer tmpbuffer
(with-output-to-string
(princ (buffer-string))
(kill-buffer))))
But there's a trailing newline in the string returned. I'm not sure how to get rid of it.
I think you can do
(replace-regexp-in-string "\n$" ""
(shell-command-to-string "git rev-parse --show-toplevel"))
If you only want to remove a newline at the very end of the output, use
(replace-regexp-in-string "\n\\'" ""
(shell-command-to-string "git rev-parse --show-toplevel"))
The accepted answer also replaces pairs of newlines ("\n\n") in the output by single newlines ("\n"), because $ matches at the end of the string or after a newline, while \\' only matches at the end of the string.
Assuming it is stored in a variable output-string, the final newline at the end can be removed this way:
(substring output-string 0 -1)
With the shell-command way, it would look like this:
(substring
(shell-command-to-string "git rev-parse --show-toplevel")
0 -1)
If You are OK with awesome external package.
use s-trim
ELISP> (shell-command-to-string "light -G")
"60.00\n"
ELISP> (s-trim (shell-command-to-string "light -G"))
"60.00"
I Have been looking on the internet but without finding a solution (hard to know what to serach for). I want a way to show "current value" on an input. Similar to what read -e -p "something: " -i "this" $variable does but in Busybox sh. As that option only became available in Bash4 which is not default. I will have to solve it another way. Not sure if this is possible..
read -p "Select by entering an number: " ANS
case $ANS in
1 ) ANS="%R | %a %d %b" ;;
2 ) ANS="%R, %a %d %b" ;;
3 ) read -p "Enter a custom string (ex. %R): " ANS ;;
4 ) ANS="%R" ;;
* ) read -p "Just answer with a number between 1 to 4. Aborting!" end; exit 0 ;;
esac
What i want is that case #3 will show the current value of the file. Ex. If the file has %R as current value. Then that is what i want it to show on input for user to interactively change it.
Until you can give us examples of what you want the programme to take as an 'input' and then give as an 'output', I suggest you read TLPD's section on 'read'