- [[#set-font-sizes-for-each-header-level-in-org][Set font sizes for each header level in Org]]
- [[#org-export][Org-export]]
- [[#org-journal][Org-journal]]
- [[#org-publish][Org-publish]]
- [[#org-roam][Org-roam]]
- [[#password-store][PASSWORD STORE]]
- [[#perspective][PERSPECTIVE]]
- [[#rainbow-mode][RAINBOW MODE]]
- [[#registers][REGISTERS]]
- [[#shells][SHELLS]]
- [[#splits][SPLITS]]
- [[#winner-mode][WINNER MODE]]
- [[#zap-to-char][ZAP TO CHAR]]
* ABOUT THIS CONFIG
This is my personal Doom Emacs config. Doom Emacs is a distribution of Emacs that uses the "evil" keybindings (Vim keybindings) and includes a number of nice extensions and a bit of configuration out of the box. I am maintaining this config not just for myself, but also for those that want to explore some of what is possible with Emacs. I will add a lot of examples of plugins and settings, some of them I may not even use personally. I do this because many people following me on YouTube look at my configs as "documentation". This config is a fork of DistroTube's config.
* BOOKMARKS AND BUFFERS
Doom Emacs uses 'SPC b' for keybindings related to bookmarks and buffers.
** Bookmarks
Bookmarks are somewhat like registers in that they record positions you can jump to. Unlike registers, they have long names, and they persist automatically from one Emacs session to the next. The prototypical use of bookmarks is to record where you were reading in various files.
#+BEGIN_SRC emacs-lisp
(map! :leader
(:prefix ("b". "buffer")
:desc "List bookmarks" "L" #'list-bookmarks
:desc "Save current bookmarks to bookmark file" "w" #'bookmark-save))
#+END_SRC
** Buffers
Regarding /buffers/, the text you are editing in Emacs resides in an object called a /buffer/. Each time you visit a file, a buffer is used to hold the file’s text. Each time you invoke Dired, a buffer is used to hold the directory listing. /Ibuffer/ is a program that lists all of your Emacs /buffers/, allowing you to navigate between them and filter them.
| ibuffer-unmark-forward | Unmark the buffer | u |
| ibuffer-do-kill-on-deletion-marks | Kill the marked buffers | x |
| ibuffer-filter-by-content | Ibuffer filter by content | f c |
| ibuffer-filter-by-directory | Ibuffer filter by directory | f d |
| ibuffer-filter-by-filename | Ibuffer filter by filename (full path) | f f |
| ibuffer-filter-by-mode | Ibuffer filter by mode | f m |
| ibuffer-filter-by-name | Ibuffer filter by name | f n |
| ibuffer-filter-disable | Disable ibuffer filter | f x |
| ibuffer-do-kill-lines | Hide marked buffers | g h |
| ibuffer-update | Restore hidden buffers | g H |
#+begin_src emacs-lisp
(evil-define-key 'normal ibuffer-mode-map
(kbd "f c") 'ibuffer-filter-by-content
(kbd "f d") 'ibuffer-filter-by-directory
(kbd "f f") 'ibuffer-filter-by-filename
(kbd "f m") 'ibuffer-filter-by-mode
(kbd "f n") 'ibuffer-filter-by-name
(kbd "f x") 'ibuffer-filter-disable
(kbd "g h") 'ibuffer-do-kill-lines
(kbd "g H") 'ibuffer-update)
#+end_src
* CALENDAR
Let's make a 12-month calendar available so we can have a calendar app that, when we click on time/date in xmobar, we get a nice 12-month calendar to view.
This is a modification of: http://homepage3.nifty.com/oatu/emacs/calendar.html
See also: https://stackoverflow.com/questions/9547912/emacs-calendar-show-more-than-3-months
:desc "Scroll year calendar backward" "<left>" #'dt/scroll-year-calendar-backward
:desc "Scroll year calendar forward" "<right>" #'dt/scroll-year-calendar-forward)
(defalias 'year-calendar 'dt/year-calendar)
#+end_src
Let's also play around with calfw.
#+begin_src emacs-lisp
(use-package! calfw)
(use-package! calfw-org)
#+end_src
* CENTAUR-TABS
To use tabs in Doom Emacs, be sure to uncomment "tabs" in Doom's init.el. Displays tabs at the top of the window similar to tabbed web browsers such as Firefox. I don't actually use tabs in Emacs. I placed this in my config to help others who may want tabs. In the default configuration of Doom Emacs, 'SPC t' is used for "toggle" keybindings, so I choose 'SPC t c' to toggle centaur-tabs. The "g" prefix for keybindings is used for a bunch of evil keybindings in Doom, but "g" plus the arrow keys were not used, so I thought I would bind those for tab navigation. But I did leave the default "g t" and "g T" intact if you prefer to use those for centaur-tabs-forward/backward.
This setting ensures that emacsclient always opens on *dashboard* rather than *scratch*.
#+begin_src emacs-lisp
(setq doom-fallback-buffer "*dashboard*")
#+end_src
* DIRED
Dired is the file manager within Emacs. Below, I setup keybindings for image previews (peep-dired). Doom Emacs does not use 'SPC d' for any of its keybindings, so I've chosen the format of 'SPC d' plus 'key'.
One of the media players available for Emacs is emms, which stands for Emacs Multimedia System. By default, Doom Emacs does not use 'SPC a',' so the format I use for these bindings is 'SPC a' plus 'key'.
:desc "Go to emms playlist" "a" #'emms-playlist-mode-go
:desc "Emms pause track" "x" #'emms-pause
:desc "Emms stop track" "s" #'emms-stop
:desc "Emms play previous track" "p" #'emms-previous
:desc "Emms play next track" "n" #'emms-next))
#+END_SRC
* EMOJIS
Emojify is an Emacs extension to display emojis. It can display github style emojis like :smile: or plain ascii ones like :).
#+begin_src emacs-lisp
(use-package emojify
:hook (after-init . global-emojify-mode))
#+end_src
* EVALUATE ELISP EXPRESSIONS
Changing some keybindings from their defaults to better fit with Doom Emacs, and to avoid conflicts with my window managers which sometimes use the control key in their keybindings. By default, Doom Emacs does not use 'SPC e' for anything, so I choose to use the format 'SPC e' plus 'key' for these (I also use 'SPC e' for 'eww' keybindings).
:desc "Evaluate last sexpression" "l" #'eval-last-sexp
:desc "Evaluate elisp in region" "r" #'eval-region))
#+END_SRC
* EWW
EWW is the Emacs Web Wowser, the builtin browser in Emacs. Below I set urls to open in a specific browser (eww) with browse-url-browser-function. By default, Doom Emacs does not use 'SPC e' for anything, so I choose to use the format 'SPC e' plus 'key' for these (I also use 'SPC e' for 'eval' keybindings). I chose to use 'SPC s w' for eww-search-words because Doom Emacs uses 'SPC s' for 'search' commands.
Some custom functions to insert the date. The function 'insert-todays-date' can be used one of three different ways: (1) just the keybinding without the universal argument prefix, (2) with one universal argument prefix, or (3) with two universal argument prefixes. The universal argument prefix is 'SPC-u' in Doom Emacs (C-u in standard GNU Emacs). The function 'insert-any-date' only outputs to one format, which is the same format as 'insert-todays-date' without a prefix.
=NOTE:= If the setting for 'ivy-posframe-display' is set to 'nil' (false), anything that is set to 'ivy-display-function-fallback' will just default to their normal position in Doom Emacs (usually a bottom split). However, if this is set to 't' (true), then the fallback position will be centered in the window.
(ivy-posframe-mode 1) ; 1 enables posframe-mode, 0 disables it.
#+END_SRC
** IVY KEYBINDINGS
By default, Doom Emacs does not use 'SPC v', so the format I use for these bindings is 'SPC v' plus 'key'.
#+BEGIN_SRC emacs-lisp
(map! :leader
(:prefix ("v" . "Ivy")
:desc "Ivy push view" "v p" #'ivy-push-view
:desc "Ivy switch view" "v s" #'ivy-switch-view))
#+END_SRC
* LINE SETTINGS
I set comment-line to 'SPC TAB TAB' which is a rather comfortable keybinding for me on my ZSA Moonlander keyboard. The standard Emacs keybinding for comment-line is 'C-x C-;'. The other keybindings are for commands that toggle on/off various line-related settings. Doom Emacs uses 'SPC t' for "toggle" commands, so I choose 'SPC t' plus 'key' for those bindings.
The modeline is the bottom status bar that appears in Emacs windows. For more information on what is available to configure in the Doom modeline, check out:
doom-modeline-persp-name t ;; adds perspective name to modeline
doom-modeline-persp-icon t) ;; adds folder icon next to persp name
#+end_src
* MOUSE SUPPORT
Adding mouse support in the terminal version of Emacs.
#+begin_src emacs-lisp
(xterm-mouse-mode 1)
#+end_src
* NEOTREE
Neotree is a file tree viewer. When you open neotree, it jumps to the current file thanks to neo-smart-open. The neo-window-fixed-size setting makes the neotree width be adjustable. Doom Emacs had no keybindings set for neotree. Since Doom Emacs uses 'SPC t' for 'toggle' keybindings, I used 'SPC t n' for toggle-neotree.
:desc "Open directory in neotree" "d n" #'neotree-dir)
#+END_SRC
* OPEN SPECIFIC FILES
Keybindings to open files that I work with all the time using the find-file command, which is the interactive file search that opens with 'C-x C-f' in GNU Emacs or 'SPC f f' in Doom Emacs. These keybindings use find-file non-interactively since we specify exactly what file to open. The format I use for these bindings is 'SPC =' plus 'key' since Doom Emacs does not use 'SPC ='.
I wrapped most of this block in (after! org). Without this, my settings might be evaluated too early, which will result in my settings being overwritten by Doom's defaults. I have also enabled org-journal, org-superstar and org-roam by adding (+journal +pretty +roam2) to the org section of my Doom Emacs init.el.
=NOTE:= I have the location of my Org directory and Roam directory in $HOME/nc/ which is a Nextcloud folder that allows me to instantly sync all of my Org work between my home computer and my office computer.
org-todo-keywords ; This overwrites the default Doom org-todo-keywords
'((sequence
"TODO(t)" ; A task that is ready to be tackled
"BLOG(b)" ; Blog writing assignments
"GYM(g)" ; Things to accomplish at the gym
"PROJ(p)" ; A project that contains other tasks
"VIDEO(v)" ; Video assignments
"WAIT(w)" ; Something is holding up this task
"|" ; The pipe necessary to separate "active" states and "inactive" states
"DONE(d)" ; Task has been completed
"CANCELLED(c)" )))) ; Task has been cancelled
#+END_SRC
** Set font sizes for each header level in Org
You can set the Org heading levels to be different font sizes. So I choose to have level 1 headings to be 140% in height, level 2 to be 130%, etc. Other interesting things you could play with include adding :foreground color and/or :background color if you want to override the theme colors.
| org-roam-find-file | org roam find file | SPC n r f |
| org-roam-insert | org roam insert | SPC n r i |
| org-roam-dailies-find-date | org roam dailies find date | SPC n r d d |
| org-roam-dailies-find-today | org roam dailies find today | SPC n r d t |
| org-roam-dailies-find-tomorrow | org roam dailies find tomorrow | SPC n r d m |
| org-roam-dailies-find-yesterday | org roam dailies find yesterday | SPC n r d y |
#+begin_src emacs-lisp
(after! org-roam
(setq org-roam-directory "~/nc/Roam"))
#+end_src
* PASSWORD STORE
Uses the standard Unix password store "pass".
#+begin_src emacs-lisp
(use-package! password-store)
#+end_src
* PERSPECTIVE
Perspective provides multiple named workspaces (or "perspectives") in Emacs, similar to having multiple desktops in window managers like Awesome and XMonad. Each perspective has its own buffer list and its own window layout, making it easy to work on many separate projects without getting lost in all the buffers. Switching to a perspective activates its window configuration, and when in a perspective, only its buffers are available (by default). Doom Emacs uses 'SPC some_key' for binding some of the perspective commands, so I used this binging format for the perspective bindings that I created..
:desc "Switch to perspective NAME" "DEL" #'persp-switch
:desc "Switch to buffer in perspective" "," #'persp-switch-to-buffer
:desc "Switch to next perspective" "]" #'persp-next
:desc "Switch to previous perspective" "[" #'persp-prev
:desc "Add a buffer current perspective" "+" #'persp-add-buffer
:desc "Remove perspective by name" "-" #'persp-remove-by-name)
#+end_src
* RAINBOW MODE
Rainbox mode displays the actual color for any hex value color. It's such a nice feature that I wanted it turned on all the time, regardless of what mode I am in. The following creates a global minor mode for rainbow-mode and enables it.
Emacs registers are compartments where you can save text, rectangles and positions for later use. Once you save text or a rectangle in a register, you can copy it into the buffer once or many times; once you save a position in a register, you can jump back to that position once or many times. The default GNU Emacs keybindings for these commands (with the exception of counsel-register) involves 'C-x r' followed by one or more other keys. I wanted to make this a little more user friendly, and since I am using Doom Emacs, I choose to replace the 'C-x r' part of the key chords with 'SPC r'.
I set splits to default to opening on the right using 'prefer-horizontal-split'. I set a keybinding for 'clone-indirect-buffer-other-window' for when I want to have the same document in two splits. The text of the indirect buffer is always identical to the text of its base buffer; changes made by editing either one are visible immediately in the other. But in all other respects, the indirect buffer and its base buffer are completely separate. For example, I can fold one split but other will be unfolded.
#+BEGIN_SRC emacs-lisp
(defun prefer-horizontal-split ()
(set-variable 'split-height-threshold nil t)
(set-variable 'split-width-threshold 40 t)) ; make this as low as needed
:desc "Clone indirect buffer other window" "b c" #'clone-indirect-buffer-other-window)
#+END_SRC
* WINNER MODE
Winner mode has been included with GNU Emacs since version 20. This is a global minor mode and, when activated, it allows you to “undo” (and “redo”) changes in the window configuration with the key commands 'SCP w <left>' and 'SPC w <right>'.
#+BEGIN_SRC emacs-lisp
(map! :leader
(:prefix ("w" . "window")
:desc "Winner redo" "<right>" #'winner-redo
:desc "Winner undo" "<left>" #'winner-undo))
#+END_SRC
* ZAP TO CHAR
Emacs provides a 'zap-to-char' command that kills from the current point to a character. It is bound to 'M-z' in standard GNU Emacs but since Doom Emacs uses 'SPC' as its leader key and does not have 'SPC z' binded to anything, it just makes since to use it for 'zap-to-char'. Note that 'zap-to-char' can be used with the universal argument 'SPC u' to modify its behavior. Examples of 'zap-to-char' usage are listed in the table below:
| SPC z e | deletes all chars to the next occurrence of 'e' |
| SPC u 2 SPC z e | deletes all chars to the second occurrence of 'e' |
| SPC u - SPC z e | deletes all chars to the previous occurrence of 'e' |
| SPC u -2 SPC z e | deletes all chars to the fourth previous occurrence of 'e' |
| SPC u 1 0 0 SPC u SPC z e | deletes all chars to the 100th occurrence of 'e' |
=TIP:= The universal argument (SPC u) can only take a single integer by default. If you need to use a multi-digit number (like 100 in the last example in the table above), then you must terminate the universal argument with another 'SPC u' after typing the number.
'zap-up-to-char' is an alternative command that does not zap the char specified. It is binded to 'SPC Z'. It can also be used in conjunction with the universal argument 'SPC u' in similar fashion to the the 'zap-to-char' examples above.
=NOTE:= Vim (evil mode) has similar functionality builtin. You can delete to the next occurrence of 'e' by using 'dte' in normal. To delete to the next occurrence of 'e' including the 'e', then you would use 'dfe'. And you can modify 'dt' and 'df' by prefixing them with numbers, so '2dte' would delete to the second occurrence of 'e'.