• Home
  • Blog
  • Bookshelf
  • Evergreen
  • About

Previous post Next post Back to top Share post

  • TODO Emacs configurations [4/7]
  • Setup before everything else
  • Performance Monitoring
  • Keep .emacs.d clean
  • Personal Setting
    • helper function
      • Open configuration file
      • Open bookmark capture
    • Auto Tangle
  • Package System Setup
    • use-package
    • straigt.el
      • Bootstrap
      • Setup
  • Genseral
    • Some general settings
    • UI setting
      • Misc
      • Face
      • Most general setting
  • Org-roam
    • Basic config
    • Consult-roam
    • Org-download
    • Org-noter + Pdf-tool
    • Epub reading
    • Org-bibtex
      • bibtex completion system
      • org-roam-bibtex
      • template
      • other-setting
    • Org-roam-ui
  • Org-protocol
  • Agenda
    • Basic Setup
    • Super-agenda
  • Editing
    • Grammar Check
    • Syntax Highlighting
    • Undo Tree
    • Magit
  • Programming
    • Exec-path-from-shell
    • Python
  • Others
    • Completion
      • Miniframe (with vertico + Nono)
      • Vertico
      • Embark
      • Company
      • Pair
      • Which-key
      • Snippet
    • Terminal
      • Eshell
    • Obsidian
    • For File navigation
    • Svg-subject
    • Helpful
    • Movement and editing
      • Consult
      • Multi-editing
      • Misc
    • Project
    • Dired
  • Export
    • Blogging with ox-hugo
    • CV with Org-mode
      • moderncv
  • Email
    • Set mu4e theme

Emacs Configuration

2022-10-29 (Updated: 2023-01-15)
24 minute read
emacs , config

Rewrite my config to get rid of the redunant functions and build the system from stratch using straight.el for package management.

TODO Emacs configurations [4/7]

  • ox-json + pyorg to obtain json data from org files, check org ele API also
  • Install blink-search and explore it.
  • Check on embark to see if it’s an alternative to which-key
  • Install Projectile
  • rewrite the super-agenda to make it nicer.
  • improvement of performance of emacs (not really… but I tried…)
  • reconfiuring eshell

Setup before everything else

1(setq package-enable-at-startup nil)
2(setq fill-column 2000)

Performance Monitoring

Define a function that will monitor how long it takes for Emacs to startup:

  • Also checks The startup steps summary.
1(defun efs/display-startup-time ()
2  (message "Emacs loaded in %s with %d garbage collections."
3           (format "%.2f seconds"
4                   (float-time
5                   (time-subtract after-init-time before-init-time)))
6           gcs-done))
7
8(add-hook 'emacs-startup-hook #'efs/display-startup-time)

Keep .emacs.d clean

 1    ;; Change the user-emacs-directory to keep unwanted things out of ~/.emacs.d
 2;; NOTE: If you want to move everything out of the ~/.emacs.d folder
 3;; reliably, set `user-emacs-directory` before loading no-littering!
 4;(setq user-emacs-directory "~/.cache/emacs")
 5
 6;; (use-package no-littering)
 7
 8;; no-littering doesn't set this by default so we must place
 9;; auto save files in the same path as it uses for sessions
10;; (setq auto-save-file-name-transforms
11;; 			`((".*" ,(no-littering-expand-var-file-name "auto-save/") t)))

Personal Setting

helper function

Open configuration file

To quickly open my configuration org file. I have a alias setting in my zshconfig too named emacsconfig which opens my init.el in VsCode, allowing me to quickly edit my init files to open emacs correctly (I am very bad at debug in emacs and I personally find this way easier).

1(defun joz/myconfig ()
2  "open my personal config"
3  (interactive)
4  (switch-to-buffer (find-file-noselect "~/.dotfiles/Emacs.org")))

Open bookmark capture

Open captured information from browser:

1(defun joz/mycapture ()
2  "Open my captued info from interent"
3  (interactive)
4  (switch-to-buffer (find-file-noselect "~/Notes/captures.org")))

Auto Tangle

1(defun joz/org-babel-tangle-config ()
2  (when (string-equal (buffer-file-name)
3    (expand-file-name "~/.dotfiles/Emacs.org"))
4  (let ((org-confim-babel-evaluate t))
5    (org-babel-tangle))))

Package System Setup

use-package

  • GitRepo for the documentations.
  • See quick tutorial for how to use use-package

use-package is a way to organize the code neat and also by defer loading of packages it will improve the start up time of emacs. Typical pacakges that implies defering loading of packages includes: :command , :bind, :hook, :defer, if one package is needed to be run at the start up time, using :demand to make sure the package is get loaded.

straigt.el

  • Note taken on [2022-11-03 Thu 21:38] Better way of organizing the package, according to system crafter, better switch to straight.el once and for all to avoice weird behavior. Make sure to backup the current init.el first.

straight.el needs to be bootstrapped into the system. There’s motivation in using it because it makes life easier for installing package from Git repo.

Bootstrap

 1(defvar bootstrap-version)
 2(let ((bootstrap-file
 3       (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
 4      (bootstrap-version 5))
 5  (unless (file-exists-p bootstrap-file)
 6    (with-current-buffer
 7        (url-retrieve-synchronously
 8         "https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
 9         'silent 'inhibit-cookies)
10      (goto-char (point-max))
11      (eval-print-last-sexp)))
12  (load bootstrap-file nil 'nomessage))
13
14(straight-use-package 'org)
15(straight-use-package 'use-package)
16
17(setq straight-use-package-by-default t)

Upgrade straight package using straight-pull-all.

Setup

 1;; From this point on we should be able to use `use-package
 2(use-package straight
 3  :config
 4  (setq straight-host-usernames '((github . "ChloeZhou1997"))) ; Move to personal information?
 5  ;; Make sure packages do not pull in internal org, we pregister org from straight.el
 6  (straight-register-package 'org)
 7  (straight-register-package 'org-contrib)
 8  :custom (straight-use-package-by-default t))
 9
10(use-package use-package-ensure-system-package)   ; because we are in use-package config
11(use-package bind-key)                  ; Load early, but see section [[Key bindings]]
12;; (setq straight-use-package-by-default t)

Genseral

Some general settings

Auto-revert, save history etc to improve general usage

 1;; Revert buffers when the underlying file has changed
 2(global-auto-revert-mode 1)
 3
 4;; Revert Dired and other buffers
 5(setq global-auto-revert-non-file-buffers t)
 6
 7;;save what you enter into minibuffer prompts
 8(setq history-length 25)
 9(savehist-mode 1)
10
11;; Remember and restore the last cursor location of opened files
12(save-place-mode 1)
13
14;; Turn on auto-fill-mode so the paragraph doesn't get super long
15(add-hook 'org-mode-hook 'turn-on-auto-fill)
16
17;; Turn of the electric indent mode
18(electric-indent-mode -1)

Using shit to switch between windows:

1(windmove-default-keybindings)

Use ibuffer to nevigate the buffers:

1;;use ibuffer
2(defalias 'list-buffers 'ibuffer-other-window) ;;open another buffer window

UI setting

Misc

1;; flash cursor lines when scroll
2(use-package beacon
3  :config
4  (beacon-mode 2))

Face

  • Font

    The :height stands for the height of the font, which also determines the size of the font.

    1;; Set the default face to larger font.
    2;; (set-face-attribute 'default nil :font "Fira Code" :height 100)
    3
    4;;Set the fixed pitch face
    5;; (set-face-attribute 'fixed-pitch nil :font "Fira Code" :height 100)
    6
    7;; Set the variable pitch face
    8;; (set-face-attribute 'variable-pitch nil :font "Fira Code" :height 1 :weight 'regular)
    

    Define a font-setup function

     1;; (defun org-font-setup ()
     2;; 	;; Set faces for heading levels
     3;; 	(dolist (face '((org-level-1 . 1.2)
     4;; 									(org-level-2 . 1.1)
     5;; 									(org-level-3 . 1.05)
     6;; 									(org-level-4 . 1.0)
     7;; 									(org-level-5 . 0.8)
     8;; 									(org-level-6 . 0.8)
     9;; 									(org-level-7 . 0.8)
    10;; 									(org-level-8 . 0.8)))
    11;; 		(set-face-attribute (car face) nil :font "Fira Code" :weight 'regular :height (cdr face)))
    12
    13  ;; Ensure that anything that should be fixed-pitch in Org files appears that way
    14;; 	(set-face-attribute 'org-block nil :foreground nil  :inherit 'fixed-pitch)
    15;; 	(set-face-attribute 'org-code nil   :inherit '(shadow fixed-pitch))
    16;; 	(set-face-attribute 'org-table nil   :inherit '(shadow fixed-pitch))
    17;; 	(set-face-attribute 'org-verbatim nil :inherit '(shadow fixed-pitch))
    18;; 	(set-face-attribute 'org-special-keyword nil :inherit '(font-lock-comment-face fixed-pitch))
    19;; 	(set-face-attribute 'org-meta-line nil :inherit '(font-lock-comment-face fixed-pitch))
    20;; 	(set-face-attribute 'org-checkbox nil :inherit 'fixed-pitch))
    21
    22;; (add-hook 'org-mode-hook 'org-font-setup)
    
  • Beautify

     1;;replace list hyphen with dot
     2(font-lock-add-keywords 'org-mode
     3                        '(("^ *\\([-]\\) "
     4                           (0 (prog1 () (compose-region (match-beginning 1) (match-end 1) "•"))))))
     5;;add emphasis markets at the end of the list
     6(setq org-ellipsis " ▼"
     7      org-hide-emphasis-markers t)
     8
     9(use-package org-bullets
    10  :hook
    11  (org-mode . (lambda () (org-bullets-mode 1)))
    12  (org-mode . (lambda ()
    13                "Beautify Org Checkbox Symbol"
    14                (push '("[ ]" . "☐" ) prettify-symbols-alist)
    15                (push '("[X]" . "☑" ) prettify-symbols-alist)
    16                (push '("[-]" . "⊡" ) prettify-symbols-alist)
    17                (prettify-symbols-mode))))
    
  • Theme

    • Doom bundled

      Use :ensure to make sure the all-the-icons package will be autoinstalled when doom-themes is installed.

       1
       2;; (use-package treemacs)
       3;; (use-package all-the-icons)
       4;; (use-package minions
       5;; 	:config (minions-mode 1))
       6
       7;;dometheme
       8
       9;; (use-package doom-themes
      10;; 	:config
      11;; 	(load-theme 'doom-one t)
      12;; 	;; all-the-icons has to be installed, enabling custom neotree theme
      13;; 	(doom-themes-neotree-config)
      14;; 	;; for treemacs user
      15;; 	(setq doom-themes-treemacs-theme "doom-atom")
      16;; 	(doom-themes-treemacs-config)
      17;; 	;;conrrect the org-mode's native fontification
      18;; 	(doom-themes-org-config))
      

      Also, use doom-modeline to prettify the mode-line section

      1;; (use-package doom-modeline
      2;; 	:ensure t
      3;; 	:init (doom-modeline-mode 1)
      4;; 	:hook (after-init . doom-modeline-mode)
      5;; 	:custom
      6;; 	(doom-modeline-height 10)
      7;; 	(doom-modeline-enable-word-count nil)
      8;; 	(doom-modeline-minor-modes t))
      
    • Nano theme

       1;; nano writer theme
       2(setq nano-font-family-monospaced "Roboto Mono")
       3(setq nano-font-family-proportional nil)
       4(setq nano-font-size 17)
       5
       6(use-package nano-base-colors
       7  :straight (nano-emacs :host github :repo "rougier/nano-emacs")
       8  :config
       9  ;; (require 'nano-theme-dark)
      10  ;; (require 'nano-theme)
      11  (require 'nano-faces)
      12  (require 'nano-modeline)
      13  (require 'nano-layout)
      14  (require 'nano-session)
      15  (require 'nano-colors)
      16  (require 'nano-writer)
      17  (require 'nano-help))
      18
      19(use-package nano-theme
      20  :straight (nano-theme :host github :repo "rougier/nano-theme"))
      21
      22(nano-mode)
      23(nano-faces)
      24
      25;; (nano-theme-set-dark)
      26;; (nano-theme)
      27(nano-modeline)
      

Most general setting

Stuff like get rid of the tool-bar, splashing lines etc.

 1;; Don't show the splash screen
 2(setq inhibit-splash-screen t)
 3;; Don't show startup message
 4(setq inhibit-startup-message t)
 5;; don't flash when the bell rings
 6(setq visible-bell nil)
 7;; hide the tool-bar-mode
 8(tool-bar-mode -1)
 9;;diable the scrool bar
10(scroll-bar-mode -1)
11;;short form of yes or no
12(fset 'yes-or-no-p 'y-or-n-p)
13;;when displaying picture, don't display actual size(they can be huge)
14(setq org-image-actual-width nil)
15;;show line number on the left of the window
16(global-display-line-numbers-mode 1)
17;;store the recently opened files in order
18(recentf-mode 1)
19;; Don't pop up UI dialogs when prompting
20(setq use-dialog-box nil)
21;; The the global scale tab-width
22(setq-default tab-width 2)

By defult, Mac use option for meta key, and Command for super-key, I’d like to swap the functionality of it:

1;; Set the option, command key to corresponding emacs key
2(setq mac-command-modifier      'meta
3      mac-option-modifier       'super
4      mac-right-option-modifier 'hyper)

Org-mode code block related setting:

1(setq   org-src-tab-acts-natively t
2        org-confirm-babel-evaluate nil
3        org-edit-src-content-indentation 0)

To disable the auto indentation in org-mode

Org-roam

Basic config

The straight version of org is not working, using straight to make sure using the built-in version

 1(use-package org
 2  ;; :straight (
 3  ;; 	org :type built-in
 4  ;; )
 5  :mode ("\\.org" . org-mode)
 6  :hook ((org-mode . turn-on-visual-line-mode)
 7         (org-mode . company-mode))
 8  :bind
 9  ("C-c a" . org-agenda)
10  ("C-c l"   . 'org-store-link)
11  ("C-c C-l"  . 'org-insert-link))
12
13;;load babel after org has loaded
14(with-eval-after-load 'org
15  (org-babel-do-load-languages
16      'org-babel-load-languages
17      '((emacs-lisp . t)
18      (python . t))))
 1;;The official one has deprecated, use self-defined one instead.
 2(defun org-roam-node-insert-immediate (arg &rest args)
 3  (interactive "P")
 4  (let ((args (cons arg args))
 5        (org-roam-capture-templates (list (append (car org-roam-capture-templates)
 6                                                  '(:immediate-finish t)))))
 7    (apply #'org-roam-node-insert args)))
 8
 9
10
11(use-package org-roam
12  :after org
13  :config
14  (org-roam-setup)
15  :custom
16  (org-roam-directory "~/Notes/RoamNotes")
17  (org-roam-completion-everywhere t)
18  (org-roam-file-extensions '("org" "md"))
19  (org-roam-completion-system 'vertico)
20  :bind (("C-c n l" . org-roam-buffer-toggle)
21         ("C-c n f" . org-roam-node-find)
22         ("C-c n i" . org-roam-node-insert)
23         ("C-c n I" . org-roam-node-insert-immediate)
24         ("C-M-i" . completion-at-point)
25         ("C-c n t" . org-roam-tag-add)
26         ("C-c n a" . org-roam-alias-add)))
27
28;;add tag in the node-find mini-buffer
29(setq org-roam-node-display-template
30      (concat "${title:*} "
31              (propertize "${tags:10}" 'face 'org-tag)))

Consult-roam

 1(use-package consult-org-roam
 2   :after org-roam
 3   :init
 4   ;; Activate the minor mode
 5   (consult-org-roam-mode)
 6   :custom
 7   ;; Use `ripgrep' for searching with `consult-org-roam-search'
 8   (consult-org-roam-grep-func #'consult-ripgrep)
 9   ;; Display org-roam buffers right after non-org-roam buffers
10   ;; in consult-buffer (and not down at the bottom)
11   (consult-org-roam-buffer-after-buffers t)
12   :config
13   ;; Eventually suppress previewing for certain functions
14   (consult-customize
15    consult-org-roam-forward-links
16    :preview-key (kbd "M-."))
17   :bind
18   ;; Define some convenient keybindings as an addition
19   ("C-c n e" . consult-org-roam-file-find)
20   ("C-c n b" . consult-org-roam-backlinks)
21   ("C-c n l" . consult-org-roam-forward-links)
22   ("C-c n r" . consult-org-roam-search))

Org-download

 1(use-package org-download
 2  :custom
 3  (org-download-method 'directory)
 4  (org-download-image-dir "~/Notes/static/images")
 5  (org-download-heading-lvl 0)
 6  (org-download-timestamp "org_%Y%m%d-%H%M%S_")
 7  (org-image-actual-width 400)
 8  (org-download-screenshot-method "xclip -selection clipboard -t image/png -o > '%s'")
 9  (org-download-image-html-width 500)
10  (org-download-image-org-width 500)
11  :bind
12  ("C-M-y" . org-download-clipboard))

Org-noter + Pdf-tool

 1(use-package pdf-tools)
 2(pdf-tools-install) ;;it has to be called otherwise org-noter won't integrate.
 3(use-package org-noter
 4  :bind
 5  ("C-c n o" . org-noter))
 6
 7(use-package org-pdftools
 8  :hook (org-mode . org-pdftools-setup-link))
 9
10(use-package org-noter-pdftools
11  :after org-noter
12  :config
13  ;; Add a function to ensure precise note is inserted
14  (defun org-noter-pdftools-insert-precise-note (&optional toggle-no-questions)
15    (interactive "P")
16    (org-noter--with-valid-session
17     (let ((org-noter-insert-note-no-questions (if toggle-no-questions
18                                                   (not org-noter-insert-note-no-questions)
19                                                 org-noter-insert-note-no-questions))
20           (org-pdftools-use-isearch-link t)
21           (org-pdftools-use-freepointer-annot t))
22       (org-noter-insert-note (org-noter--get-precise-info)))))
23
24  ;; fix https://github.com/weirdNox/org-noter/pull/93/commits/f8349ae7575e599f375de1be6be2d0d5de4e6cbf
25  (defun org-noter-set-start-location (&optional arg)
26    "When opening a session with this document, go to the current location.
27With a prefix ARG, remove start location."
28    (interactive "P")
29    (org-noter--with-valid-session
30     (let ((inhibit-read-only t)
31           (ast (org-noter--parse-root))
32           (location (org-noter--doc-approx-location (when (called-interactively-p 'any) 'interactive))))
33       (with-current-buffer (org-noter--session-notes-buffer session)
34         (org-with-wide-buffer
35          (goto-char (org-element-property :begin ast))
36          (if arg
37              (org-entry-delete nil org-noter-property-note-location)
38            (org-entry-put nil org-noter-property-note-location
39                           (org-noter--pretty-print-location location))))))))
40  (with-eval-after-load 'pdf-annot
41    (add-hook 'pdf-annot-activate-handler-functions #'org-noter-pdftools-jump-to-note)))

Epub reading

1(use-package nov)
2(setq nov-unzip-program (executable-find "bsdtar")
3      nov-unzip-args '("-xC" directory "-f" filename))
4(add-to-list 'auto-mode-alist '("\\.epub\\'" . nov-mode))

Org-bibtex

bibtex completion system

 1;;download  org-ref
 2(use-package org-ref)
 3
 4;;download helm completion
 5(use-package helm-bibtex
 6  :bind
 7  ("C-c h b" . helm-bibtex)
 8  :custom
 9  (bibtex-completion-bibliography '("/Users/zhouqiaohui/Documents/MyLibrary.bib"))
10  (bibtex-completion-library-path '("~/Notes/RoamNotes/Paper"))
11  (bibtex-completion-pdf-field "File")
12  (bibtex-completion-notes-path "~/Notes/RoamNotes"))

org-roam-bibtex

This allows roam like citation backlink

1(use-package org-roam-bibtex
2  :after org-roam
3  :hook org-mode)

template

  • ${slug} is by default the title of the note, it’s the text passed into the template system from the search. Also according to wikipedia,it’s the human readable part of the url.
 1(setq orb-preformat-keywords
 2      '("citekey" "title" "url" "author-or-editor" "keywords" "file")
 3      orb-process-file-keyword t
 4      orb-attached-file-extensions '("pdf"))
 5
 6(setq org-roam-capture-templates
 7      '(("r" "bibliography reference" plain
 8         (file "~/Notes/RoamNotes/Templates/cite_temp.org")
 9         :target
10         (file+head "${citekey}.org" "#+title: ${title}\n"))
11        ("t" "thought" plain
12         (file "~/Notes/RoamNotes/Templates/thought_temp.org")
13         :if-new (file+head "%<%Y%m%d%H%M%S>-${slug}.org" "#+title: ${title}\n")
14         :unnarrowed t)
15        ("d" "default" plain
16         "%?"
17         :target (file+head "%<%Y%m%d%H%M%S>-${slug}.org" "#+title: ${title}\n")
18         :unnarrowed t)
19        ))

other-setting

For the PDF Scrapper, change the formate of the paper key:

1(setq orb-autokey-format "%a%T[3]%y")

Org-roam-ui

 1(use-package org-roam-ui
 2    :after org-roam
 3;;         normally we'd recommend hooking orui after org-roam, but since org-roam does not have
 4;;         a hookable mode anymore, you're advised to pick something yourself
 5;;         if you don't care about startup time, use
 6;;  :hook (after-init . org-roam-ui-mode)
 7    :config
 8    (setq org-roam-ui-sync-theme t
 9          org-roam-ui-follow t
10          org-roam-ui-update-on-save t
11          org-roam-ui-open-on-start t))

Org-protocol

 1(server-start)
 2(add-to-list 'load-path "~/.emacs.d/straight/build/org/org-protocol.el")
 3(require 'org-protocol)
 4(setq org-directory "~/Notes/")
 5
 6(defun transform-square-brackets-to-round-ones(string-to-transform)
 7  "Transforms [ into ( and ] into ), other chars left unchanged."
 8  (concat
 9   (mapcar #'(lambda (c) (if (equal c ?[) ?\( (if (equal c ?]) ?\) c))) string-to-transform))
10  )
11
12(global-set-key (kbd "C-c c") 'org-capture)

Agenda

Basic Setup

 1(setq org-agenda-files (list "~/Notes/Agenda/dailylife.org"
 2                             "~/.dotfiles/Emacs.org"
 3                             "~/Notes/blogideas.org"
 4                             "~/Notes/Questions.org"
 5                             "~/Notes/RoamNotes/readinglists.org"))
 6;;Add progress logging to the org-agenda file
 7;; (setq org-log-done 'note)
 8(setq org-log-done t)
 9;;Add captures template
10(setq org-capture-templates '(
11                              ("p" "Protocol" entry
12                               (file+headline "~/Notes/captures.org" "Inbox")
13                               "* %^{Title}\nSource: %u, %c\n #+BEGIN_QUOTE\n%i\n#+END_QUOTE\n\n\n%?")
14                              ("L" "Protocol Link" entry
15                               (file+headline "~/Notes/captures.org" "Link")
16                               "* %? [[%:link][%(transform-square-brackets-to-round-ones \"%:description\")]]\n")
17                              ("t" "Todo" entry
18                               (file+headline "~/Notes/Agenda/dailylife.org" "Task")
19                               "* TODO %?\n %i\n")
20                              ("b" "Blog Idea" plain
21                               (file+headline "~/Notes/blogideas.org" "Inbox")
22                               (file "~/Notes/RoamNotes/Templates/blog_temp.org")
23                               )
24                              ("f" "emacs problem" plain
25                               (file+headline "~/Notes/captures.org" "Emacs Problems")
26                               "- [ ] %?\n")
27                              ))
28
29;;set todo keywords
30(setq org-todo-keywords
31      '((sequence "TODO(t)" "|" "DONE(d)")
32        (sequence "TOREAD(t@/!)" "READING(r@/!)" "|" "CANCELLED(c)" "STALLED(s)" "DONE(d)")
33        (sequence "|" "CANCELED(c)")))
34
35;;set faces
36(setq org-todo-keyword-faces
37      '(("TODO" . (:foreground "white" :background "#238B22" :weight bold))
38        ("READING" . "yellow")
39        ("TOREAD" . (:forground "#779ECE" :background "black" :weight bold))
40        ("QUE" . (:foreground "red" :background "white" :weight bold))
41        ("SOMEDAY" . (:forground "#CABCB5" :underline t))))

Super-agenda

 1(use-package org-ql)
 2(use-package org-super-agenda
 3  :hook org-agenda-mode)
 4
 5(setq org-super-agenda-groups
 6      '((:name "Priority"
 7               :tag "priority"
 8               :face (:foreground "#E1B896"  :underline t))
 9        (:name "Reading List"
10               :file-path "~/Notes/RoamNotes/readinglists.org"
11               :todo "READING")
12        (:name "Research"
13               :and (
14                     :tag "research"
15                          :not (
16                                :todo ("SOMEDAY" "PROJECT"))))
17        (:name "Learning"
18               :and(:tag "learning"
19                         :not (:todo ("PROJECT" "NEXT"))))
20        (:name "Questions to answer"
21               :todo "QUE")
22        (:name "Long term plan"
23               :and(:todo "PROJECT"
24                          :children t))))

Editing

Grammar Check

1(use-package lsp-grammarly
2  :hook (text-mode . (lambda ()
3                       (require 'lsp-grammarly)
4                       (lsp))))  ; or lsp-deferred
5(use-package flymake)
6(define-key flymake-mode-map (kbd "M-n") 'flymake-goto-next-error)
7(define-key flymake-mode-map (kbd "M-p") 'flymake-goto-prev-error)

Syntax Highlighting

1(use-package rainbow-delimiters
2  :hook (prog-mode . rainbow-delimiters-mode))

Undo Tree

1(use-package undo-tree
2:ensure t
3:init
4(global-undo-tree-mode))

Magit

1(use-package magit
2  :defer t)

Programming

Exec-path-from-shell

1(use-package exec-path-from-shell)
2(setq exec-path-from-shell-variables '("PATH"))
3  (exec-path-from-shell-initialize)

Python

1(use-package python-mode
2  :custom
3  (python-shell-interpreter "/opt/homebrew/opt/[email protected]/bin/python3.10"))
4(setq python-shell-completion-native-enable nil)
5(setq org-babel-python-command "python3")

Others

Completion

Miniframe (with vertico + Nono)

  1;; Nicolas .P Rougier emacs configuration - mini-frame configuration
  2;; ---------------------------------------------------------------------
  3(use-package vertico)
  4(use-package mini-frame)
  5
  6(defun minibuffer-setup ()
  7
  8  ;; This prevents the header line to spill over second line
  9  (let ((inhibit-message t))
 10    (toggle-truncate-lines 1))
 11
 12  (setq enable-recursive-minibuffers t)
 13
 14  ;; This allows to have a consistent full width (fake) header like
 15  (setq display-table (make-display-table))
 16  (set-display-table-slot display-table
 17                          'truncation (make-glyph-code ?\  'nano-subtle))
 18  (set-display-table-slot display-table
 19                          'wrap (make-glyph-code ?\  'nano-subtle))
 20  (setq buffer-display-table display-table)
 21
 22  (cursor-intangible-mode)
 23  (face-remap-add-relative 'default :foreground "black")
 24  (face-remap-add-relative 'completions-first-difference :foreground "black")
 25  (let* ((left  (concat (propertize " "
 26                                    'face '(nano-subtle)
 27                                    'display '(raise +0.20))
 28                        (propertize " Minibuffer"
 29                                    'face 'nano-subtle)
 30                        (propertize " "
 31                                    'face 'nano-subtle
 32                                    'display '(raise -0.30))))
 33         (right (propertize "C-g: abort"
 34                            'face '(:inherit (nano-faded nano-subtle)
 35                                    :weight light)))
 36         (spacer (propertize (make-string (- (window-width)
 37                                             (length left)
 38                                             (length right)
 39                                             1) ?\ )
 40                             'face 'nano-subtle))
 41         (header (concat left spacer right " "))
 42         (overlay (make-overlay (+ (point-min) 0) (+ (point-min) 0))))
 43    (overlay-put overlay 'before-string
 44        (concat
 45         (propertize " " 'display header)
 46         "\n"
 47         ;; This provides a vertical gap (half a line) above the prompt.
 48         (propertize " " 'face `(:extend t)
 49                     'display '(raise .33)
 50                     'read-only t 'cursor-intangible t)))))
 51
 52 (add-hook 'minibuffer-setup-hook #'minibuffer-setup)
 53
 54
 55;; (defun minibuffer-exit ())
 56;; (add-hook 'minibuffer-exit-hook #'minibuffer-exit)
 57
 58;; Prefix/Affix the current candidate. From
 59;; https://github.com/minad/vertico/wiki#prefix-current-candidate-with-arrow
 60(defun minibuffer-format-candidate (orig cand prefix suffix index _start)
 61  (let ((prefix (if (= vertico--index index)
 62                    "  " "   ")))
 63    (funcall orig cand prefix suffix index _start)))
 64
 65(advice-add #'vertico--format-candidate
 66            :around #'minibuffer-format-candidate)
 67
 68(with-eval-after-load 'vertico
 69  (setq completion-styles '(basic substring partial-completion flex))
 70  (setq vertico-count 10)
 71  (setq vertico-count-format nil)
 72  (setq vertico-grid-separator
 73        #("  |  " 2 3 (display (space :width (1))
 74                               face (:background "#ECEFF1"))))
 75  (define-key vertico-map (kbd "<backtab>") #'minibuffer-complete)
 76  (set-face-attribute 'vertico-current nil
 77                      :inherit '(nano-strong nano-subtle))
 78  (set-face-attribute 'completions-first-difference nil
 79                      :inherit '(nano-default))
 80  (set-face-attribute 'minibuffer-prompt nil
 81                      :inherit '(nano-default nano-strong))
 82  (setq minibuffer-prompt-properties
 83        '(read-only t cursor-intangible t face minibuffer-prompt))
 84
 85  (defun vertico--prompt-selection ()
 86    "Highlight the prompt"
 87    (let ((inhibit-modification-hooks t))
 88      (set-text-properties (minibuffer-prompt-end) (point-max)
 89                           '(face (nano-strong nano-salient))))))
 90
 91(with-eval-after-load 'marginalia
 92  (setq truncate-string-ellipsis "…")
 93  (setq marginalia--ellipsis "…")
 94  (setq marginalia-align 'right)
 95  (setq marginalia-align-offset -1))
 96
 97
 98(with-eval-after-load 'mini-frame
 99  (set-face-background 'child-frame-border (face-foreground 'nano-faded))
100  (setq mini-frame-default-height vertico-count)
101  (setq mini-frame-create-lazy t)
102  (setq mini-frame-show-parameters 'mini-frame-dynamic-parameters)
103  (setq mini-frame-ignore-commands
104        '("edebug-eval-expression" debugger-eval-expression))
105  (setq mini-frame-internal-border-color (face-foreground 'nano-subtle-i))
106  ;; (setq mini-frame-resize 'grow-only) ;; -> buggy as of 01/05/2021
107  ;; (setq mini-frame-resize 'not-set)
108  ;; (setq mini-frame-resize nil)
109  (setq mini-frame-resize t)
110  (setq mini-frame-resize-min-height 3)
111
112
113  (defun mini-frame-dynamic-parameters ()
114    (let* ((edges       (window-pixel-edges))      ;; (left top right bottom)
115           (body-edges  (window-body-pixel-edges)) ;; (left top right bottom)
116           (left   (nth 0 edges))      ;; Take margins into account
117           (top    (nth 1 edges)) ;; Drop header line
118           (right  (nth 2 edges))      ;; Take margins into account
119           (bottom (nth 3 body-edges)) ;; Drop header line
120           (left   (if (eq left-fringe-width 0)
121                       left
122                     (- left (frame-parameter nil 'left-fringe))))
123           (right  (nth 2 edges))
124           (right  (if (eq right-fringe-width 0)
125                       right
126                     (+ right (frame-parameter nil 'right-fringe))))
127           (fringe-left 0)
128           (fringe-right 0)
129           (border 1)
130           ;; (width (- (frame-pixel-width) (* 2 (+ fringe border))))
131           (width (- right left fringe-left fringe-right (* 0 border)))
132           (y (- top border)))
133    `((left . ,(- left border))
134      (top . ,y)
135      (alpha . 1.0)
136      (width . (text-pixels . ,width))
137      (left-fringe . ,fringe-left)
138      (right-fringe . ,fringe-right)
139      (child-frame-border-width . ,border)
140      (internal-border-width . ,border)
141      (foreground-color . ,(face-foreground 'nano-default))
142      (background-color . ,(face-background 'highlight)))))
143  )
144
145(custom-set-variables
146 '(mini-frame-show-parameters
147   '((top . 10)
148     (width . 0.7)
149     (left . 0.5))))
150
151(mini-frame-mode)

Vertico

Minimalistic auto completion setting: vertico + savehist + marginalia Reference to this tutorial.

 1;;enable Vertico
 2(use-package vertico
 3  :custom
 4  (vertico-count 13)
 5  (vertico-resize t)
 6  (vertico-cycle nil)
 7  ;; Extensions
 8  (vertico-grid-separator "       ")
 9  (vertico-grid-lookahead 50)
10  (vertico-buffer-display-action '(display-buffer-reuse-window))
11  (vertico-multiform-categories
12   '((file reverse)
13     (consult-grep buffer)
14     (consult-location)
15     (imenu buffer)
16     (library reverse indexed)
17     (org-roam-node reverse indexed)
18     (t reverse)
19     ))
20  (vertico-multiform-commands
21   '(("flyspell-correct-*" grid reverse)
22     (org-refile grid reverse indexed)
23     (consult-yank-pop indexed)
24     (consult-lsp-diagnostics)
25     ))
26  :bind
27  (:map vertico-map
28        ( "?" . minibuffer-completion-help)
29        ("M-RET" . minibuffer-force-complete)
30        ("M-TAB" . minibuffer-complete)
31        ("C-M-n" . vertico-next-group)
32        ("C-M-p" . vertico-previous-group)
33        )
34  :hook ((rfn-eshadow-update-overlay . vertico-directory-tidy) ; Clean up file path when typing
35         ))
36
37(vertico-mode)
38(nano-dark)
39
40;; Persist history over Emacs restarts. Vertico sorts by history position.
41(use-package savehist
42  :init
43  (savehist-mode))
44
45;; Show info of files at the marginal
46(use-package marginalia
47  :after vertico
48  :custom
49  (marginalia-annotators '(marginalia-annotators-heavy marginalia-annotators-light nil))
50  :init
51  (marginalia-mode))
52
53;;icon's completion in minibuffer
54(use-package all-the-icons-completion
55  :after (marginalia all-the-icons)
56  :hook (marginalia-mode . all-the-icons-completion-marginalia-setup)
57  :init
58  (all-the-icons-completion-mode))
59
60;; Optionally use the `orderless' completion style, so no need to worry about the
61;; order of keywords when trying to search for command.
62(use-package orderless
63  :init
64  ;; Configure a custom style dispatcher (see the Consult wiki)
65  ;; (setq orderless-style-dispatchers '(+orderless-dispatch)
66  ;;       orderless-component-separator #'orderless-escapable-split-on-space)
67  (setq completion-styles '(orderless basic)
68        completion-category-defaults nil
69        completion-category-overrides '((file (styles partial-completion)))))
70
71(setq read-file-name-completion-ignore-case t
72      read-buffer-completion-ignore-case t
73      completion-ignore-case t)

Embark

 1(use-package embark
 2  :bind
 3  (("C-." . embark-act)         ;; pick some comfortable binding
 4   ("C-:" . embark-dwim)        ;; good alternative: M-.
 5   ("C-h B" . embark-bindings)) ;; alternative for `describe-bindings'
 6  :init
 7  ;; Optionally replace the key help with a completing-read interface
 8  (setq prefix-help-command #'embark-prefix-help-command)
 9  :config
10  ;; Hide the mode line of the Embark live/completions buffers
11  (add-to-list 'display-buffer-alist
12               '("\\`\\*Embark Collect \\(Live\\|Completions\\)\\*"
13                 nil
14                 (window-parameters (mode-line-format . none)))))
15
16;; Consult users will also want the embark-consult package.
17(use-package embark-consult
18  :hook
19  (embark-collect-mode . consult-preview-at-point-mode))

Company

 1(use-package company
 2  :init
 3  (global-company-mode)
 4  :custom
 5  (company-minimum-prefix-length 2)
 6  (company-idle-delay 0.25)
 7  (company-backends '((company-capf company-semantic company-keywords company-etags company-dabbrev-code company-yasnippet)))
 8  (company-files-exclusions '(".git/" ".DS_Store"))
 9  :bind
10  (:map company-active-map
11        ("C-n" . company-select-next)
12        ("C-p" . company-select-previous)))

Pair

1(use-package smartparens
2  :config
3  (smartparens-global-mode t))

Which-key

This package offer all the possible completions for the prefix.

1(use-package which-key
2  :config (which-key-mode))

Snippet

 1(defun my-org-mode-hook ()
 2  (setq-local yas-buffer-local-condition
 3              '(not (org-in-src-block-p t))))
 4
 5(use-package yasnippet
 6  :init
 7  (yas-global-mode 1)
 8  :custom
 9  (yas-snippet-dirs '("~/.emacs.d/snippets"
10                      "~/.emacs.d/straight/repos/yasnippet-snippets/snippets"))
11  :bind
12  ("\C-o" . yas-expand)
13  :config
14  (add-hook 'org-mode-hook 'my-org-mode-hook))
15
16;;download snippets lib
17(use-package yasnippet-snippets)
18
19;;integration with consult
20(use-package consult-yasnippet)

Terminal

Eshell

Some links about eshell configuration and tutorial: Eshell Aliases, Prompt and colors, shell setup gitrepo.

 1(defun efs/configure-eshell ()
 2  ;; Save command history when commands are entered
 3  (add-hook 'eshell-pre-command-hook 'eshell-save-some-history)
 4  ;; Truncate buffer for performance
 5  (add-to-list 'eshell-output-filter-functions 'eshell-truncate-buffer)
 6
 7  (setq eshell-history-size         10000
 8        eshell-buffer-maximum-lines 10000
 9        eshell-hist-ignoredups t
10        eshell-scroll-to-bottom-on-input t))
11
12(use-package eshell-git-prompt)
13
14(use-package eshell
15  :bind
16  (:map eshell-mode-map
17        ("C-r" . consult-history)
18        ("<home>" . eshell-bol))
19  :hook (eshell-first-time-mode . efs/configure-eshell)
20  :config
21  (eshell-git-prompt-use-theme 'powerline))
22
23(use-package esh-autosuggest
24  :hook (eshell-mode . esh-autosuggest-mode))

Obsidian

 1(use-package obsidian
 2  :config
 3  (obsidian-specify-path "~/Library/Mobile Documents/com~apple~CloudDocs/Obsidian/Research")
 4  (global-obsidian-mode t)
 5  :custom
 6  ;; This directory will be used for `obsidian-capture' if set.
 7  (obsidian-inbox-directory "Inbox")
 8  :bind (:map obsidian-mode-map
 9  ;; Replace C-c C-o with Obsidian.el's implementation. It's ok to use another key binding.
10  ("C-c C-o" . obsidian-follow-link-at-point)
11  ;; Jump to backlinks
12  ("C-c C-b" . obsidian-backlink-jump)
13  ;; If you prefer you can use `obsidian-insert-link'
14  ("C-c C-l" . obsidian-insert-wikilink)))

link: https://github.com/zzamboni/vita/

For File navigation

1(use-package deadgrep
2  :bind
3  ("C-c n d" . deadgrep))

Svg-subject

 1(use-package svg)
 2(use-package svg-tag-mode)
 3(use-package svg-lib)
 4
 5(defun svg-font-lock-tag (label)
 6  (svg-lib-tag label nil :margin 0))
 7
 8(defun svg-font-lock-todo ()
 9  (svg-lib-tag "TODO" nil :margin 0
10               :font-family "Roboto Mono" :font-weight 500
11               :foreground "#FFFFFF" :background "#673AB7"))
12
13(defun svg-font-lock-done ()
14  (svg-lib-tag "DONE" nil :margin 0
15               :font-family "Roboto Mono" :font-weight 400
16               :foreground "#B0BEC5" :background "white"))
17
18(defun svg-font-lock-progress_percent (value)
19  (svg-image (svg-lib-concat
20              (svg-lib-progress-bar (/ (string-to-number value) 100.0)
21                                nil :margin 0 :stroke 2 :radius 3 :padding 2 :width 12)
22              (svg-lib-tag (concat value "%")
23                           nil :stroke 0 :margin 0)) :ascent 'center))
24
25(defun svg-font-lock-progress_count (value)
26  (let* ((seq (mapcar #'string-to-number (split-string value "/")))
27         (count (float (car seq)))
28         (total (float (cadr seq))))
29  (svg-image (svg-lib-concat
30              (svg-lib-progress-bar (/ count total) nil
31                                :margin 0 :stroke 2 :radius 3 :padding 2 :width 12)
32              (svg-lib-tag value nil
33                           :stroke 0 :margin 0)) :ascent 'center)))
34
35(defvar svg-font-lock-keywords
36  `(("TODO"
37     (0 (list 'face nil 'display (svg-font-lock-todo))))
38    ("\\:\\([0-9a-zA-Z]+\\)\\:"
39     (0 (list 'face nil 'display (svg-font-lock-tag (match-string 1)))))
40    ("DONE"
41     (0 (list 'face nil 'display (svg-font-lock-done))))
42    ("\\[\\([0-9]\\{1,3\\}\\)%\\]"
43     (0 (list 'face nil 'display (svg-font-lock-progress_percent (match-string 1)))))
44    ("\\[\\([0-9]+/[0-9]+\\)\\]"
45     (0 (list 'face nil 'display (svg-font-lock-progress_count (match-string 1)))))))
46
47;; Activate
48(push 'display font-lock-extra-managed-props)
49(font-lock-add-keywords 'org-mode svg-font-lock-keywords)
50(font-lock-flush (point-min) (point-max))

Helpful

1(use-package helpful
2  :bind
3  ("C-h f" . helpful-callable)
4  ("C-h v" . helpful-variable)
5  ("C-h k" . helpful-key)
6  ("C-h o" . helpful-symbol))

Movement and editing

Consult

 1;;define prefix C-s for search map
 2(define-prefix-command 'search-map)
 3(global-set-key (kbd "C-s") 'search-map)
 4
 5(use-package consult
 6  :bind
 7  ("C-x b" . consult-buffer)
 8  ("M-y" . consult-yank-pop)
 9  (:map search-map
10        ("s" . consult-line)
11        ("l" . consult-goto-line)
12        ("o" . consult-outline)
13        ("S" . consult-line-multi)))

Multi-editing

1(use-package iedit
2  :bind
3  ("C-;" . iedit-mode))
4
5(use-package multiple-cursors
6  :bind
7  ("C-x C-;" . mc/mark-all-like-this)
8  ("C-x r l" . mc/edit-lines))

Misc

1;;expand region basiced semantics
2(use-package expand-region
3  :bind
4  ("C-=" . er/expand-region))

Project

1(use-package projectile
2  :config
3  (setq projectile-project-search-path '("~/Blogs" "~/Desktop/ZeroToMastery"))
4  (setq projectile-switch-project-action #'projectile-dired)
5  :bind
6  (:map projectile-mode-map
7        ("s-p" . projectile-command-map)
8        ("C-c p" . projectile-command-map)))

Integration with consult:

1(use-package consult-projectile
2  :straight (consult-projectile :type git :host gitlab :repo "OlMon/consult-projectile" :branch "master")
3  :after projectile)

Dired

 1
 2(use-package all-the-icons-dired)
 3(use-package dired-rainbow
 4  :defer 2
 5  :config
 6  (dired-rainbow-define-chmod directory "#6cb2eb" "d.*")
 7  (dired-rainbow-define html "#eb5286" ("css" "less" "sass" "scss" "htm" "html" "jhtm" "mht" "eml" "mustache" "xhtml"))
 8  (dired-rainbow-define xml "#f2d024" ("xml" "xsd" "xsl" "xslt" "wsdl" "bib" "json" "msg" "pgn" "rss" "yaml" "yml" "rdata"))
 9  (dired-rainbow-define document "#9561e2" ("docm" "doc" "docx" "odb" "odt" "pdb" "pdf" "ps" "rtf" "djvu" "epub" "odp" "ppt" "pptx"))
10  (dired-rainbow-define markdown "#ffed4a" ("org" "etx" "info" "markdown" "md" "mkd" "nfo" "pod" "rst" "tex" "textfile" "txt"))
11  (dired-rainbow-define database "#6574cd" ("xlsx" "xls" "csv" "accdb" "db" "mdb" "sqlite" "nc"))
12  (dired-rainbow-define media "#de751f" ("mp3" "mp4" "mkv" "MP3" "MP4" "avi" "mpeg" "mpg" "flv" "ogg" "mov" "mid" "midi" "wav" "aiff" "flac"))
13  (dired-rainbow-define image "#f66d9b" ("tiff" "tif" "cdr" "gif" "ico" "jpeg" "jpg" "png" "psd" "eps" "svg"))
14  (dired-rainbow-define log "#c17d11" ("log"))
15  (dired-rainbow-define shell "#f6993f" ("awk" "bash" "bat" "sed" "sh" "zsh" "vim"))
16  (dired-rainbow-define interpreted "#38c172" ("py" "ipynb" "rb" "pl" "t" "msql" "mysql" "pgsql" "sql" "r" "clj" "cljs" "scala" "js"))
17  (dired-rainbow-define compiled "#4dc0b5" ("asm" "cl" "lisp" "el" "c" "h" "c++" "h++" "hpp" "hxx" "m" "cc" "cs" "cp" "cpp" "go" "f" "for" "ftn" "f90" "f95" "f03" "f08" "s" "rs" "hi" "hs" "pyc" ".java"))
18  (dired-rainbow-define executable "#8cc4ff" ("exe" "msi"))
19  (dired-rainbow-define compressed "#51d88a" ("7z" "zip" "bz2" "tgz" "txz" "gz" "xz" "z" "Z" "jar" "war" "ear" "rar" "sar" "xpi" "apk" "xz" "tar"))
20  (dired-rainbow-define packaged "#faad63" ("deb" "rpm" "apk" "jad" "jar" "cab" "pak" "pk3" "vdf" "vpk" "bsp"))
21  (dired-rainbow-define encrypted "#ffed4a" ("gpg" "pgp" "asc" "bfe" "enc" "signature" "sig" "p12" "pem"))
22  (dired-rainbow-define fonts "#6cb2eb" ("afm" "fon" "fnt" "pfb" "pfm" "ttf" "otf"))
23  (dired-rainbow-define partition "#e3342f" ("dmg" "iso" "bin" "nrg" "qcow" "toast" "vcd" "vmdk" "bak"))
24  (dired-rainbow-define vc "#0074d9" ("git" "gitignore" "gitattributes" "gitmodules"))
25  (dired-rainbow-define-chmod executable-unix "#38c172" "-.*x.*"))
26
27(use-package dired-single
28  :defer t)
29
30(use-package dired-ranger
31  :defer t)
32
33(use-package dired-collapse
34  :defer t)
35
36
37(use-package dired-single)
38
39(use-package all-the-icons-dired
40  :hook (dired-mode . all-the-icons-dired-mode))
41
42(use-package dired-open
43  :config
44  ;; Doesn't work as expected!
45  ;;(add-to-list 'dired-open-functions #'dired-open-xdg t)
46  (setq dired-open-extensions '(("png" . "feh")
47                                ("mkv" . "mpv"))))

Export

Blogging with ox-hugo

1(use-package ox-hugo
2  :after ox
3  :config
4  (setq org-hugo-link-desc-insert-type t)
5  (setq org-export-with-broken-links t))

CV with Org-mode

moderncv

1(use-package ox-altacv
2  :straight (org-cv :type git :host gitlab :repo "ChloeZhou1997/org-cv"))
3
4(use-package ox-awesomecv
5  :straight (org-cv :type git :host gitlab :repo "ChloeZhou1997/org-cv"))

Email

  1(use-package mu4e
  2  :straight (:host github
  3                    :files ("build/mu4e/*.el")
  4                    :branch "master"
  5                    :repo "djcb/mu"
  6                    :pre-build (("meson" "build")
  7                                ("ninja" "-C" "build"))))
  8
  9(require 'smtpmail)
 10
 11;; we installed this with homebrew
 12(setq mu4e-mu-binary (executable-find "mu"))
 13
 14;; this is the directory we created before:
 15(setq mu4e-maildir "~/.maildir")
 16
 17;; this command is called to sync imap servers:
 18(setq mu4e-get-mail-command "mbsync -a")
 19;; how often to call it in seconds:
 20(setq mu4e-update-interval 300)
 21
 22;; save attachment to desktop by default
 23;; or another choice of yours:
 24(setq mu4e-attachment-dir "~/Desktop")
 25
 26;; rename files when moving - needed for mbsync:
 27(setq mu4e-change-filenames-when-moving t)
 28
 29(setq mu4e-drafts-folder "/[Gmail]/Drafts")
 30(setq mu4e-sent-folder "/[Gmail]/Sent Mail")
 31(setq mu4e-refile-folder "/[Gmail]/All Mail")
 32(setq mu4e-refile-folder "/[Gmail]/Trash")
 33
 34;; list of your email adresses:
 35(setq mu4e-user-mail-address-list '("[email protected]"))
 36
 37;; check your ~/.maildir to see how the subdirectories are called
 38;; for the generic imap account:
 39;; e.g `ls ~/.maildir/example'
 40(setq   mu4e-maildir-shortcuts
 41        '(("/INBOX" . ?g)
 42          ("/[Gmail]/Sent Mail" . ?G)))
 43
 44;; the following is to show shortcuts in the main view.
 45;; (add-to-list 'mu4e-bookmarks
 46;;              (mu4e-bookmark-define
 47;; 							"Inbox - Gmail"
 48;;               "maildir:/gmail/INBOX"
 49;; 							"?g"))
 50
 51;;context
 52;; (setq mu4e-contexts
 53;;       `(,(make-mu4e-context
 54;;           :name "gmail"
 55;;           :enter-func
 56;;           (lambda () (mu4e-message "Enter [email protected] context"))
 57;;           :leave-func
 58;;           (lambda () (mu4e-message "Leave [email protected] context"))
 59;;           :match-func
 60;;           (lambda (msg)
 61;;             (when msg
 62;;               (mu4e-message-contact-field-matches msg
 63;;                                                   :to "[email protected]")))
 64;;           :vars '((user-mail-address . "[email protected]")
 65;;                   (user-full-name . "qiaohui zhou")
 66;;                   (mu4e-drafts-folder . "/[Gmail]/Drafts")
 67;;                   (mu4e-sent-folder . "/[Gmail]/Sent Mail")
 68;;                   (mu4e-trash-folder . "/[Gmail]/Trash")))))
 69
 70(setq mu4e-context-policy 'pick-first) ;; start with the first (default) context;
 71(setq mu4e-compose-context-policy 'ask) ;; ask for context if no context matches;
 72
 73;; gpg encryptiom & decryption:
 74;; this can be left alone
 75(require 'epa-file)
 76(epa-file-enable)
 77(setq epa-pinentry-mode 'loopback)
 78(auth-source-forget-all-cached)
 79
 80;; don't keep message compose buffers around after sending:
 81(setq message-kill-buffer-on-exit t)
 82
 83;; send function:
 84(setq send-mail-function 'sendmail-send-it
 85      message-send-mail-function 'sendmail-send-it)
 86
 87;; send program:
 88;; this is exeranal. remember we installed it before.
 89(setq sendmail-program (executable-find "msmtp"))
 90
 91;; select the right sender email from the context.
 92(setq message-sendmail-envelope-from 'header)
 93
 94;; chose from account before sending
 95;; this is a custom function that works for me.
 96;; well I stole it somewhere long ago.
 97;; I suggest using it to make matters easy
 98;; of course adjust the email adresses and account descriptions
 99(defun timu/set-msmtp-account ()
100  (if (message-mail-p)
101      (save-excursion
102        (let*
103            ((from (save-restriction
104                     (message-narrow-to-headers)
105                     (message-fetch-field "from")))
106             (account
107              (cond
108               ((string-match "[email protected]" from) "gmail"))))
109          (setq message-sendmail-extra-arguments (list '"-a" account))))))
110
111(add-hook 'message-send-mail-hook 'timu/set-msmtp-account)
112
113;; mu4e cc & bcc
114;; this is custom as well
115(add-hook 'mu4e-compose-mode-hook
116          (defun timu/add-cc-and-bcc ()
117            "My Function to automatically add Cc & Bcc: headers.
118    This is in the mu4e compose mode."
119            (save-excursion (message-add-header "Cc:\n"))
120            (save-excursion (message-add-header "Bcc:\n"))))
121
122;; mu4e address completion
123(add-hook 'mu4e-compose-mode-hook 'company-mode)
124
125;;optional
126;; store link to message if in header view, not to header query:
127(setq org-mu4e-link-query-in-headers-mode nil)
128;; don't have to confirm when quitting:
129(setq mu4e-confirm-quit nil)
130;; number of visible headers in horizontal split view:
131(setq mu4e-headers-visible-lines 20)
132;; don't show threading by default:
133(setq mu4e-headers-show-threads nil)
134;; hide annoying "mu4e Retrieving mail..." msg in mini buffer:
135(setq mu4e-hide-index-messages t)
136;; customize the reply-quote-string:
137(setq message-citation-line-format "%N @ %Y-%m-%d %H:%M :\n")
138;; M-x find-function RET message-citation-line-format for docs:
139(setq message-citation-line-function 'message-insert-formatted-citation-line)
140;; by default do not show related emails:
141(setq mu4e-headers-include-related nil)
142;; by default do not show threads:
143(setq mu4e-headers-show-threads nil)

Set mu4e theme

1;; (use-package mu4e-thread-folding
2;; 	:straight(mu4e-thread-folding :host github :repo "rougier/mu4e-thread-folding"))
3
4;; (use-package mu4e-dashboard
5;; 	:straight(mu4e-dashboard :host github :repo "rougier/mu4e-dashboard"))
6
7;; (use-package nano-mu4e
8;; 	:straight (nano-emacs :host github :repo "rougier/nano-emacs"))

Links to this note

  • Configuring org-protocol in AMD build MacOS
  • Learning Elisp 02 Variable and Scope
  • Learning Elisp 03 Reading and Writing Buffer in Emacs
  • Lisp Project - Dotcrafter
  • Home
  • Blog
  • Bookshelf
  • Evergreen
  • About
  • TODO Emacs configurations [4/7]
  • Setup before everything else
  • Performance Monitoring
  • Keep .emacs.d clean
  • Personal Setting
    • helper function
      • Open configuration file
      • Open bookmark capture
    • Auto Tangle
  • Package System Setup
    • use-package
    • straigt.el
      • Bootstrap
      • Setup
  • Genseral
    • Some general settings
    • UI setting
      • Misc
      • Face
      • Most general setting
  • Org-roam
    • Basic config
    • Consult-roam
    • Org-download
    • Org-noter + Pdf-tool
    • Epub reading
    • Org-bibtex
      • bibtex completion system
      • org-roam-bibtex
      • template
      • other-setting
    • Org-roam-ui
  • Org-protocol
  • Agenda
    • Basic Setup
    • Super-agenda
  • Editing
    • Grammar Check
    • Syntax Highlighting
    • Undo Tree
    • Magit
  • Programming
    • Exec-path-from-shell
    • Python
  • Others
    • Completion
      • Miniframe (with vertico + Nono)
      • Vertico
      • Embark
      • Company
      • Pair
      • Which-key
      • Snippet
    • Terminal
      • Eshell
    • Obsidian
    • For File navigation
    • Svg-subject
    • Helpful
    • Movement and editing
      • Consult
      • Multi-editing
      • Misc
    • Project
    • Dired
  • Export
    • Blogging with ox-hugo
    • CV with Org-mode
      • moderncv
  • Email
    • Set mu4e theme
Menu TOC share Top
Copyright © 2023 Chloe Jo
  • Home
  • Blog
  • Bookshelf
  • Evergreen
  • About