Emacs
Much Ado About Emacs 009
Moving away from Evil
Conceptually it reminds me of fog. When I am in Emacs, trying to write, there seems to be an invisible curtain keeping me detached from the program. That is the effect evil-mode has on me. Yes, I love the space-bar leader key. But the actual writing and editing is foggy. Part of it is due to my limited knowledge of VIM keybindings but a part of it is the fact that I am putting a layer of complexity between Emacs and me. It feels like a stream of worry. Anxiety. Uncomfortable.
I decided to move back to god-mode and do away with evil-mode. VIM keybindings are fantastic and they are useful but I am not in VIM, I am in Emacs. I decided to not introduce this layer of discomfort into the process and deal with pure, vanilla Emacs.
So, it is back to vanilla Emacs. To the Emacs tutorial.
I decided to try to replicate the space-bar configuration through general.el and used the leader-key M-o
.
#+begin_src emacs-lisp
(general-create-definer my-leader-def
:prefix "M-o"
:non-normal-prefix "M-o")
(my-leader-def
;; Top level functions
"." '(find-file :which-key "find file")
";" '(consult-recent-file :which-key "recent files")
"/" '(bufferfile-rename :which-key "rename file")
"TAB" '(switch-to-prev-buffer :which-key "previous buffer")
"p" '(org-capture :which-key "org-capture")
"x" '(execute-extended-command :which-key "execute command")
;; Applications
"a" '(nil :which-key "applications")
"ao" '(org-agenda :which-key "org-agenda")
"ac" '(org-capture :which-key "org-capture")
"ab" '(nil :which-key "browse url")
"abc" '(browse-url-chrome :which-key "chrome")
"abg" '(my/er-google :which-key "google search")
"av" '(nil :which-key "avy")
"avc" '(avy-goto-char-timer :which-key "avy goto char")
"avp" '(avy-goto-parens :which-key "avy goto parens")
"ad" '(dired :which-key "dired")
;; Buffers
"b" '(nil :which-key "buffer")
"bb" '(switch-to-buffer :which-key "switch-to-buffer")
"bc" '(consult-buffer :which-key "consult-buffer")
"bd" '(kill-buffer :which-key "kill-buffer")
"bi" '(ibuffer :which-key "ibuffer")
"bn" '(next-buffer :which-key "next-buffer")
"bp" '(previous-buffer :which-key "previous-buffer")
"bR" '(revert-buffer :which-key "revert-buffer")
"br" '(bufferfile-rename :which-key "rename buffer")
"bs" '(scratch :which-key "scratch buffer")
;;Consult
"c" '(nil :which-key "consult")
"cb" '(nil :which-key "bookmark/buffer")
"cd" '(consult-dir :which-key "con dir")
"cg" '(consult-grep :which-key "con grep")
"ch" 'consult-org-heading :which-key "con org heading"
"cl" '(consult-line :which-key "con line")
"cn" '(consult-notes :which-key "con notes")
"co" '(consult-outline :which-key "con outline")
"cy" '(consult-yasnippet :which-key "con yasnippet")
"cb" '(nil :which-key "bookmark/buffer")
"cbo" '(consult-bookmark :which-key "con bookmark")
"cbu" '(consult-buffer :which-key "con buffer")
;;Consult-register
"cr" '(nil :which-key "consult-register")
"crr" '(consult-register :which-key "con register")
"crs" '(consult-register-store :which-key "con reg store")
;; Denote
"d" '(nil :which-key "denote")
"dl" '(denote-link :which-key "denote-link")
"dL" '(denote-add-links :which-key "denote-add-links")
"dn" '(denote :which-key "denote")
"db" '(denote-backlinks :which-key "denote-backlinks")
"dr" '(denote-rename-file :which-key "denote-rename-file")
"dR" '(denote-rename-file-using-front-matter :which-key "denote-rename-file-using-front-matter")
;;Elfeed
"e" '(nil :which-key "elfeed")
"ee" '(elfeed :which-key "elfeed")
"eu" '(elfeed-update :which-key "elfeed-update")
;; Files
"f" '(nil :which-key "files")
"ff" '(find-file :which-key "find file")
"fs" '(save-buffer :which-key "save buffer")
"fS" '(write-file :which-key "write file")
"fd" '(dired :which-key "dired")
"fo" '(reveal-in-osx-finder :which-key "reveal in finder")
"fR" '(consult-recent-file :which-key "recent files")
"fr" '(bufferfile-rename :which-key "rename buffer")
;; Help/emacs
"h" '(nil :which-key "help/emacs")
"hv" '(consult-describe-variable :which-key "des. variable")
"hb" '(describe-bindings :which-key "des. bindings")
"hM" '(describe-mode :which-key "des. mode")
"hf" '(consult-describe-function :which-key "des. func")
"hF" '(describe-face :which-key "des. face")
"hk" '(describe-key :which-key "des. key")
;;set-mode
"hm" '(nil :which-key "which-mode")
"hme" '(emacs-lisp-mode :which-key "elisp mode")
"hmo" '(org-mode :which-key "org mode")
"hmm" '(markdown-mode :which-key "markdown mode")
"hmt" '(text-mode :which-key "text mode")
;; Jumps
"j" '(nil :which-key "jumps")
"jr" '(jump-to-register :which-key "registers")
"jb" '(bookmark-jump :which-key "bookmark jump")
;;package
"hp" '(nil :which-key "package")
"hpr" '(package-refresh-contents)
"hpi" '(package-install)
"hpd" '(package-delete)
;; Search
"s" '(nil :which-key "search")
"sa" '(avy-goto-char-2 :which-key "avy-goto-char-2")
"ss" '(isearch-forward :which-key "isearch-forward")
"sr" '(isearch-backward :which-key "isearch-backward")
"sp" '(project-search)
"si" '(consult-imenu :which-key "consult-imenu")
"sm" '(consult-mark :which-key "jump to marker")
"sl" '(consult-goto-line :which-key "Go to line")
;;System
"m" '(nil :which-key "system")
"m1" '(restart-emacs :which-key "restart emacs")
"m+" '(tab-bar-new-tab :which-key "tab new")
"m-" '(tab-close :which-key "tab close")
"mf" '(my/resources-visit :which-key "visit resources")'
"mr" '(nil :which-key "region")
"mre" '(er/expand-region :which-key "expand region")
"mrc" '(er/contract-region :which-key "contract region")
"mp" '(nil :which-key "palimpsest")
"mpb" '(palimpsest-move-region-to-bottom :which-key "pal move bottom")
"mpt" '(palimpsest-move-region-to-top :which-key "pal move top")
"mm" '(nil :which-key "mark")
"mml" '(my/mark-line :which-key "mark line")
"mmb" '(my/mark-block :which-key "mark block")
;; Newsticker
"n" '(nil :which-key "newsticker")
"ng" '(newsticker-get-all-news :which-key "get news")
"ns" '(newsticker-show-news :which-key "show news")
"no" '(newsticker-treeview-mark-list-items-old :which-key "mark as old")
"nq" '(newsticker-treeview-quit :which-key "newsticker quit")
"nu" '(newsticker-treeview-update :which-key "treeview-update")
;; Org-mode
"o" '(nil :which-key "org-mode")
"oa" '(org-agenda :which-key "org-agenda")
"oc" '(org-capture :which-key "org-capture")
"on" '(recursive-narrow-or-widen-dwim :which-key "narrow")
"or" '(org-refile :which-key "refile")
"ot" '(org-todo :which-key "DONE")
"ou" '(my/org-jump-to-heading-beginning :which-key "jump to heading")
;; More Org
"ol" '(nil :which-key "line/link")
"olb" '(org-beginning-of-line :which-key "begin of line")
"ole" '(org-end-of-line :which-key "end of line")
"oli" '(my/org-insert-link-dwim :which-key "org insert link")
"ols" '(org-store-link :which-key "org store link")
;; Yet More org
"," '(nil :which-key "more-org")
",c" '(org-cycle :which-key "org-cycle")
",n" '(outline-next-visible-heading :which-key "next-heading")
",p" '(outline-previous-visible-heading :which-key "previous-heading")
",t" '(org-set-tags-command :which-key "set-tags")
",u" '(outline-up-heading :which-key "up-heading")
;; text and tab
"t" '(nil :which-key "text")
"tn" '(tab-next :which-key "tab next")
"tp" '(tab-previous :which-key "tab previous")
"tr" '(isearch-query-replace :which-key "find and replace")
"ts" '(yas-insert-snippet :which-key "insert yasnippet")
"tR" '(replace-regexp :which-key "replace-regexp")
"tt" '(titlecase-dwim :which-key "titlecase")
"t/" '(my/comment-or-uncomment :which-key "comment")
;; date/time
"td" '(nil :which-key "stamp date/time")
"tdd" '(my/time-stamp-short :which-key "time-stamp-short")
"tds" '(my/date-stamp :which-key "date-stamp")
;; word
"tw" '(nil :which-key "word")
"twc" '(my/copy-whole-word :which-key "copy whole word")
"twk" '(my/kill-inner-word :which-key "kill inner word")
"two" '(copy-as-format-org-mode :which-key "copy as org mode")
"twm" '(copy-as-format-markdown :which-key "copy as markdown mode")
"twi" '(org-web-tools-insert-web-page-as-entry :which-key "insert web page as entry")
"tww" '(org-web-tools-insert-link-for-url :which-key "insert link for url")
"twl" '(dictionary-lookup-definition :which-key "dictionary lookup")
"twp" '(my/lookup-word-at-point :which-key "lookup word at point")
;; Windows
"w" '(nil :which-key "window")
"wl" '(windmove-right :which-key "windmove-right")
"wh" '(windmove-left :which-key "windmove-left")
"wk" '(windmove-up :which-key "windmove-up")
"wj" '(windmove-down :which-key "windmove-down")
"wd" '(delete-window :which-key "delete-window")
"wr" '(hsplit-last-buffer :which-key "split-window-right")
"wb" '(vsplit-last-buffer :which-key "split-window-below")
;; Visual
"v" '(nil :which-key "visual")
"vt" '(consult-theme :which-key "load theme")
"vR" '(read-only-mode :which-key "read only mode"))
#+end_src
This is a work in progress. I tweak it from time to time depending on my usage.
defalias
I got exposed to this through
Defalias a quick guide to making an alias in Emacs coding - YouTube
Thank you, Raoul Comninos.
There are commands I run in Emacs only sporadically. They might or might not be bound to keyboard commands. I have to remember what the commands are and I find myself searching for them. I have assigned them an alias. I can go into command mode (M-x
), and type the alias and hit enter. The command executes. Reminds me of aliases I use in the shell.
#+begin_src emacs-lisp
(defalias 'brf 'bufferfile-rename-file)
(defalias 'pde 'package-delete)
(defalias 'pud 'auto-package-update-now)
(defalias 'rem 'restart-emacs)
#+end_src
I am going to add to this list as I go along and find more commands that are not used often but are good to alias.
recursive-narrow
Another thing I learned from Raoul. The Emacs recursive narrow package coding programming - YouTube.
Thank you Raoul.
Using recursive-narrow - MELPA. Lets me concentrate on portions of a document.
I have set it up with Raoul’s help.
#+begin_src emacs-lisp
(use-package recursive-narrow)
(defun recursive-narrow-or-widen-dwim ()
"If the region is active, narrow to that region.
Otherwise, narrow to the current function. If this has no effect,
widen the buffer. You can add more functions to
`recursive-narrow-dwim-functions'."
(interactive)
(recursive-narrow-save-position
(cond ((region-active-p) (narrow-to-region (region-beginning) (region-end)))
((run-hook-with-args-until-success 'recursive-narrow-dwim-functions))
((derived-mode-p 'prog-mode) (narrow-to-defun))
((derived-mode-p 'org-mode) (org-narrow-to-subtree)))
;; If we don't narrow
(progn
(message "Recursive settings: %d" (length recursive-narrow-settings))
(recursive-widen))))
#+end_src
It is assigned a keybinding, (C-x n n
). I have also configured it in general.el to M-o o n
. Works like a charm.
bufferfile.el
jameschertibufferfile.el Emacs helper functions to delete and rename buffer files. This is a package which provides helper functions to delete and rename buffer files:
bufferfile-rename
: Renames the file visited by the current buffer and updates the buffer name for all associated buffers, including clones/indirect buffers. It also ensures that buffer-local features referencing the file, such as Eglot, are correctly updated to reflect the new file name.bufferfile-delete
: Delete the file associated with a buffer and kill all buffers visiting the file, including clones/indirect buffers.bufferfile-copy
: Copies the file visited by the current buffer to a new file.
I use the bufferfile-rename
command multiple times a day. It might help to explain the workflow.
- I read the Letters from an American Heather Cox Richardson Substack everyday and then using a Chrome extension copy the markdown link to the entry and download the content of the entry to a Markdown file in my Downloads folder.
- I open the file in Emacs. Add the markdown link to the top of the page. Add a heading 1 item above the link. The heading is of the form “HCR - (the date of the entry)”.
- I want the file-name to be this new heading 1 entry. So, I copy it and then proceed to change the name of the file,
buffer-file-rename
and then select the name of the file and paste in the new name of the file. - Then I proceed to re-read the entry and add my comments and observations to the file.
- After I am done with it, I move it to an EagleFiler document.
This package makes the process of renaming my Emacs buffer easier. I use the following coinfiguration:
#+begin_src emacs-lisp
(use-package bufferfile
:ensure t
:vc (:url "https://github.com/jamescherti/bufferfile.el"
:rev :newest))
#+end_src
That is all I have for you today.
macosxguru at the gmail thingie.