Skip to content

lambdion/.doom.d

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Doom Emacs Configuration

;;; config.el -*- lexical-binding: t; -*-

Note that this org file will be tangled to config.el when doom sync is run, it will also be tangled when saving an org file in your $DOOMDIR (~/doom.d). See https://docs.doomemacs.org/latest/modules/config/literate/.

Remember to stage the changes from config.org and config.el when using Git.

Theme

(setq doom-theme 'doom-ayu-dark) ; set theme
;;(setq fancy-splash-image (expand-file-name "doom-emacs-gray.png" doom-user-dir)) ;  set splash image

Line Numbers

Set line numbers to True, meaning absolute line numbering will always be shown.

(setq display-line-numbers-type t)

Disable During Zen

I do not want line numbers activated while in Zen Mode (writeroom-mode)

(defun my-toggle-normal-line-numbers ()
  "Turn line numbers off if in writeroom-mode, otherwise turn on."
  (interactive)
  (if (eq writeroom-mode 't)      ; if writeroom mode is on...
      (setq display-line-numbers nil)   ; turn them off
    (setq display-line-numbers 't)))    ; otherwise turn them back on again

;;; add a hook to run this function when zen mode is activated or deactivated
(add-hook 'writeroom-mode-hook 'my-toggle-normal-line-numbers)

Font

See {C-h v doom-font} for documentation on how doom handles fonts.

(setq doom-font (font-spec :family "Noto Sans Mono Medium" :size 22) ; set defaut font
      doom-variable-pitch-font (font-spec :family "Noto Sans" :size 22) ; set variable width font
      doom-unicode-font "-GOOG-Noto Sans Mono-medium-normal-normal-*-22-*-*-*-*-0-iso10646-1") ; set unicode font

Fix Greek Characters

I had an issue with Greek characters, specifically lambda, not displaying in the correct font. This should fix it. For some reason, to actually get this to run, I had to call the function after the fact, rather than just calling it in the config. Setting it to run after eshell (the situation in which I am most likely to experiece this issue) fixes this. To fix greek characters on the fly, simply call {M-x my-greek-font-fix}.

(defun my-greek-font-fix ()
  "Set the fontset-default for Greek & Coptic"
  (interactive)
  (set-fontset-font "fontset-default"
                    (cons (decode-char 'ucs #x0370)
                          (decode-char 'ucs #x03ff))
                    "-GOOG-Noto Sans Mono-medium-normal-normal-*-22-*-*-*-*-0-iso10646-1")) ;; λe
(after! eshell
  (my-greek-font-fix))

Evil

(map! :map evil-motion-state-map
      ;; make ]] and [[ move to org headings
      "] ]" #'org-next-visible-heading
      "[ [" #'org-previous-visible-heading
      ;; make j and k use visual lines rather than actual lines, to make line wrap easier to navigate through
      "j" #'evil-next-visual-line
      "k" #'evil-previous-visual-line)

Lisp Editing

Put parinfer in paren mode by default. Parinfer in smart mode lets you indent like python and it handles the parens. This is too intrusive and doesn’t play well with other lisp editing toolkits. Parinfer in paren mode handles the indentation while leaving you control over the parens.

(after! parinfer-rust
  (setq! parinfer-rust-preferred-mode "paren"))
(after! evil-cleverparens
  (add-hook! lisp-mode 'evil-cleverparens-mode))

Add a wrapping keybind because otherwise there is none.

(map! :map lispy-mode-map
      "M-(" #'lispy-wrap-round)

Notes

Deft

Deft takes a bit of customizing to work with Org Roam, but it does indeed work very well once sorted.

(after! deft
  ;; Standard Deft Configuration
  (setq deft-extensions '("txt" "md" "org")); file extensions
  (setq deft-directory "~/res/org/roam/"); directory
  (setq deft-recursive nil); dont search directories recursively
  ;; Regexes to work with org-roam
  (setq deft-strip-summary-regexp  ; this is a regexp that processes the "file summary", so ugly metadata doesnt get displayed in the file preview
        (concat "\\("
          "^:.+:.*\n"     ; any line with a :SOMETHING:
          "\\|^#\\+.*\n"  ; any line starting with a #+
          "\\|^\\*.+.*\n" ; any line where an asterisk starts the line
          "\\|\n"         ; any newline characters, so the file summary stays on a single line
          "\\)"))
  (setq deft-strip-title-regexp    ; this is regexp that processes the title, so similar metadata is hidden, otherwise the title would always be #+title: Title
        "\\(?:^%+\\|^#\\+TITLE: *\\|^[#* ]+\\|-\\*-[[:alpha:]]+-\\*-\\|^title:[ ]*\\|#+$\\)")
  ;; Advice to use #+title metadata field as the title, rather than the first line as it is by default
  ;; Courtesy of @brittAnderson https://github.com/jrblevin/deft/issues/75#issuecomment-919578769
  (advice-add 'deft-parse-title :override
   (lambda (file contents)
       (if deft-use-filename-as-title  ; if the var to make the filename the title is true, do so
           (deft-base-filename file)
         (let* ((case-fold-search 't)  ; otherwwise, search for the line with "title:" in it
                (begin (string-match "title: " contents))
                (end-of-begin (match-end 0))
                (end (string-match "\n" contents begin)))
           (if begin
               (substring contents end-of-begin end)
             (format "%s" file)))))))

Org

The default org directory must be set before it loads, therefore it is outside the after! block

(setq org-directory "~/res/org/")
(after! org
  (add-to-list 'org-agenda-files "~/res/org/sync")
  ;; add LaTeX preview to the {SPC m} localleader map in org-mode
  (map! :map org-mode-map
        :localleader
        :n "L" #'org-latex-preview)
  (map! :map org-mode-map
        :n "M-<return>" #'my-org-meta-return))
  ;; Make M-RET enter evil insert mode
  ;; (define-key org-mode-map
              ;; [remap org-meta-return]
              ;; #'my-org-meta-return))

I’d rather M-RET on a bullet point put me in insert, so I use this wrapper function.

(defun my-org-meta-return ()
  (interactive)
  (org-meta-return)  ; The ordinary function
  (evil-insert-state)) ; Enter evil insert mode

Org Agenda

Add an option for Thursday-Wednesday week display to org-agenda.

(after! org-agenda
  (add-to-list 'org-agenda-custom-commands
               '("c" "Thursday" agenda "" ((org-agenda-span 7)
                                            (org-agenda-start-on-weekday 4)))))

Org Roam

I used to use a load of config to make org-roam nice, but then realized doom had native org support with :lang (org +roam2), so the only stuff left are my personal requirements.

Filename Update

Make it so org-roam files have their filenames updated when the metadata title is updated.

(add-hook! 'after-save-hook                                               ; Run this function upon saving
        (defun my-org-roam-rename-file-to-title ()                        ; Define function
        (when-let*
                ((old-file (buffer-file-name))
                (is-roam-file (org-roam-file-p old-file))
                (file-node (save-excursion
                        (goto-char 1)
                        (org-roam-node-at-point)))
                (slug (org-roam-node-slug file-node))
                (new-file (expand-file-name (concat slug ".org")))
                (different-name? (not (string-equal old-file new-file))))
        (org-roam-db-sync)                                                ; Sync the db
        (rename-buffer new-file)                                          ; Rename the buffer
        (rename-file old-file new-file)                                   ; Rename the file
        (set-visited-file-name new-file)                                  ; Set visited file name
        (set-buffer-modified-p t)                                         ; Set buffer modified
        (save-buffer))))                                                  ; Save

Org Roam UI

From https://github.com/org-roam/org-roam-ui#doom

(use-package! websocket
    :after org-roam)
(use-package! org-roam-ui
    :after org-roam ;; or :after org
;;         normally we'd recommend hooking orui after org-roam, but since org-roam does not have
;;         a hookable mode anymore, you're advised to pick something yourself
;;         if you don't care about startup time, use
;;  :hook (after-init . org-roam-ui-mode)
    :config
    (setq org-roam-ui-sync-theme t
          org-roam-ui-follow t
          org-roam-ui-update-on-save t
          org-roam-ui-open-on-start t))

Newlines

A function to space out lines in a file by adding a newline to every line in the buffer.

(defun my-insert-newlines ()
  "Append newline to every line in the current buffer."
  (interactive)  ; Prompt for the string
  (save-excursion  ; Save the current point position
    (goto-char (point-min))  ; Move to the beginning of the buffer
    (while (not (eobp))  ; While not at the end of the buffer
      (end-of-line)  ; Move to the end of the current line
      (insert "\n")  ; Optionally insert a newline (if you want to keep lines separate)
      (forward-line 1))))  ; Move to the next line

A modified version of org-html-export-to-html that runs the above function beforehand, for exporting files that use a single newline to separate paragrams to HTML correctly.

(defun my-org-html-export-to-html-newlines ()
  "Export current buffer to HTML file having added newlines at the end of every line."
  (interactive)
  (save-excursion
    (let ((original-content (buffer-string)))
      (my-insert-newlines)
      (org-html-export-to-html)
      (erase-buffer)
      (insert original-content))))

Hyperbole

Doing SPC h h all the time is cumbersome, and SPC y is not used for anything else.

(map! :map doom-leader-map
      "y" #'hyperbole)

Hyperbole and Org disagree over the M-RET key, so I rebind Org’s one. Hyperbole has a variable to sort out this disagreement, see {C-h v hsys-org-enable-smart-keys RET} for more info.

(after! hyperbole
  ;; Prioritze hyperbole functionality only when on a button
  (setq hsys-org-enable-smart-keys 'buttons)
  ;; Rebind org's M-RET so I can still use it even when on a hyperbole button
  (map! :map org-mode-map
      "M-s-<return>" #'my-org-meta-return))

I dont like to clutter my home dir with .directories if I can help it.

(after! hyperbole
  (setq hbmap:dir-user "~/.config/emacs/hyperbole"))

Journal

Setup formats for monthly journal using org-journal (the +journal flag in init.el).

(after! org-journal
  ;; Use a monthly format
  (setq org-journal-file-type 'monthly)
  (setq org-journal-file-format "%Y%m")                 ; filenames
  ;; Use valid org-mode timestamps in the headings and subheadings instead of plaintext dates and times
  (setq org-journal-date-format "[%Y-%m-%d %a]")        ; day headings
  (setq org-journal-time-format "[%Y-%m-%d %a %H:%M]")) ; time headings

I prefer the keybindings to be the same structure as with Org Roam.

(map! :map doom-leader-notes-map
      "j n" #'org-journal-new-entry
      "j N" #'org-journal-new-scheduled-entry
      "j f" #'org-journal-search-forever
      "j j" #'org-journal-display-entry
      "j J" #'org-journal-read-entry)

Terminals

Vterm

Set the default shell to fish

(setq vterm-shell "/bin/fish")

Eshell

There’s this cool thing called Smart Shell where your cursor gets put on the command you just executed rather than at the new prompt, meaning:

  • You can read the output of the executed command from the top down
  • You can use arrow keys to change parts of the command and reexecute the improved one
  • You can start typing to begin a new command

Janky, needs some polish for working with evil and company, but useful in some situations https://www.masteringemacs.org/article/complete-guide-mastering-eshell https://reddit.com/r/emacs/comments/cyu4is

;;(add-to-list 'load-path "~/.doom.d/lisp/")  ;; I cloned the em-smart.el to here in case
;;(require 'em-smart)  ;; this should make it work
;;(add-to-list 'eshell-modules-list 'eshell-smart)  ;; or perhaps this is making it work and the rest is unnecessary
;; either way, it works and im not touching it in case it ceases to

Other Packages

GNU APL Mode

Add gnu-apl-mode’s keyboard to Doom’s {SPC t} toggle menu.

(map! :map doom-leader-toggle-map
      "a" #'gnu-apl-show-keyboard) ; bind SPC t a to toggle the APL keyboard buffer

Calc

Add Emac’s calc to Doom’s {SPC o} open menu.

(map! :map doom-leader-open-map
      "c" #'calc                   ; calc is cool
      "C" #'full-calc)             ; rpn 💪

Which-Key?

(setq which-key-idle-delay 0.2)

Hy

hy-shell--interpreter-args is a list of arguments to pass to the Hy interpreter in a REPL like that created by run-hy. By default, as set in hy-shell.el, it is set to '("--spy"). This argument, as per $ hy --help, tells the interpreter to “print equivalent Python code before executing”. To disable this functionality, set it to nil.

;; (setq hy-shell--interpeter-args nil)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published