diff --git a/README.org b/README.org index f6bea84..a4fe474 100644 --- a/README.org +++ b/README.org @@ -167,6 +167,8 @@ the ~custom-file~ as [[info:emacs#Saving Customizations][saving customizations ( '(epg-pinentry-mode 'loopback) '(global-hl-line-mode t) '(global-hl-line-sticky-flag t) + '(history-delete-duplicates t) + '(history-length 500) '(indent-tabs-mode nil) '(inhibit-startup-buffer-menu t) '(inhibit-startup-screen t) @@ -286,34 +288,36 @@ background. #+caption: Improve the visibility of faces in =faces.el=. #+name: lst:tweak-faces-faces-after #+begin_src emacs-lisp - (defun tweak-region-face-background-color () - (when (featurep 'gtk) - (set-face-attribute - 'region nil - :background (cdr (assoc (face-attribute 'default :background) - '(("white" . "LightGoldenrod2") - ("black" . "blue3"))))))) + (with-eval-after-load 'emacs + (defun tweak-region-face-background-color () + (when (featurep 'gtk) + (set-face-attribute + 'region nil + :background (cdr (assoc (face-attribute 'default :background) + '(("white" . "LightGoldenrod2") + ("black" . "blue3"))))))) - (tweak-region-face-background-color) + (tweak-region-face-background-color)) #+end_src #+caption[Improve the visibility of faces in =org-faces.el=]: #+caption: Improve the visibility of faces in =org-faces.el=. #+name: lst:tweak-org-faces-before #+begin_src emacs-lisp - ;; Shadow the definition in org-faces.el: - (defface org-block - ;; https://emacs.stackexchange.com/questions/9600/ - ;; how-can-i-override-a-pre-defined-face-for-light-and-dark-backgrounds - `((((background dark)) - :inherit (fixed-pitch) - ,@(and (>= emacs-major-version 27) '(:extend t)) - :background "#444444") - (t - :inherit (fixed-pitch) - ,@(and (>= emacs-major-version 27) '(:extend t)) - :background "#FFFFD0")) - "My face used for text inside various blocks. + (with-eval-after-load 'emacs + ;; Shadow the definition in org-faces.el: + (defface org-block + ;; https://emacs.stackexchange.com/a/9604 answers: + ;; How to override a defined face for light and dark backgrounds? + `((((background dark)) + :inherit (fixed-pitch) + ,@(and (>= emacs-major-version 27) '(:extend t)) + :background "#444444") + (t + :inherit (fixed-pitch) + ,@(and (>= emacs-major-version 27) '(:extend t)) + :background "#FFFFD0")) + "My face used for text inside various blocks. It is always used for source blocks. You can refine what face should be used depending on the source block language by setting, @@ -321,22 +325,23 @@ background. When `org-fontify-quote-and-verse-blocks' is not nil, text inside verse and quote blocks are fontified using the `org-verse' and - `org-quote' faces, which inherit from `org-block'.") + `org-quote' faces, which inherit from `org-block'.")) #+end_src #+caption[Improve the visibility of faces in =sh-script.el=]: #+caption: Improve the visibility of faces in =sh-script.el=. #+name: lst:tweak-sh-script-faces-before #+begin_src emacs-lisp - ;; Shadow the definition in sh-script.el: - (defface sh-heredoc - '((((class color) (background dark)) - (:foreground "yellow")) - (((class color) (background light)) - (:foreground "magenta")) - (t - (:weight bold))) - "My face to show a here-document.") + (with-eval-after-load 'emacs + ;; Shadow the definition in sh-script.el: + (defface sh-heredoc + '((((class color) (background dark)) + (:foreground "yellow")) + (((class color) (background light)) + (:foreground "magenta")) + (t + (:weight bold))) + "My face to show a here-document.")) #+end_src ** [[info:emacs#Dired][Dired: directory editor as file manager (info)]] @@ -559,15 +564,16 @@ users from shooting themselves in the feet. Listing #+caption: Configure the =disabled-command-function=. #+name: lst:configure-disabled-command-function #+begin_src emacs-lisp - (setq disabled-command-function - (defun my-enable-this-command (&rest _args) - "Called when a disabled command is executed. + (with-eval-after-load 'emacs + (setq disabled-command-function + (defun my-enable-this-command (&rest _args) + "Called when a disabled command is executed. Enable it and re-execute it." - (put this-command 'disabled nil) - (message "You typed %s. %s was disabled until now." - (key-description (this-command-keys)) this-command) - (sit-for 0) - (call-interactively this-command))) + (put this-command 'disabled nil) + (message "You typed %s. %s was disabled until now." + (key-description (this-command-keys)) this-command) + (sit-for 0) + (call-interactively this-command)))) #+end_src * [[info:emacs#Emacs Server][Using Emacs as a server (info)]] @@ -703,23 +709,21 @@ file. #+caption: Enable =savehist-mode= and =vertico-mode=. #+name: lst:enable-vertico-mode #+begin_src emacs-lisp - (unless noninteractive + (when (fboundp 'savehist-mode) + (savehist-mode +1) (custom-set-variables - '(history-delete-duplicates t) - '(history-length 500) '(savehist-additional-variables '(eww-history kill-ring regexp-search-string search-ring - search-string))) - (savehist-mode +1) - (when (fboundp 'vertico-mode) - (vertico-mode +1)) - (with-eval-after-load 'vertico - (define-key vertico-map (kbd "RET") #'vertico-directory-enter) - (define-key vertico-map (kbd "DEL") #'vertico-directory-delete-char) - (define-key vertico-map (kbd "M-DEL") #'vertico-directory-delete-word))) + search-string)))) + (when (fboundp 'vertico-mode) + (vertico-mode +1)) + (with-eval-after-load 'vertico + (define-key vertico-map (kbd "RET") #'vertico-directory-enter) + (define-key vertico-map (kbd "DEL") #'vertico-directory-delete-char) + (define-key vertico-map (kbd "M-DEL") #'vertico-directory-delete-word)) #+end_src #+attr_latex: :booktabs yes :float table @@ -760,17 +764,16 @@ Listing [[lst:configure-orderless]] enables =orderless=. #+caption: Configure =orderless=. #+name: lst:configure-orderless #+begin_src emacs-lisp - (unless noninteractive - (when (fboundp 'orderless-filter) - (custom-set-variables - ;; https://github.com/purcell/emacs.d/issues/778 - '(completion-styles '(basic completion-partial orderless)) - '(completion-category-defaults nil) - '(completion-category-overrides - '((file (styles partial-completion))))) - (add-hook 'minibuffer-setup-hook - (defun my-on-minibuffer-setup-hook() - (setq-default completion-styles '(substring orderless)))))) + (when (fboundp 'orderless-filter) + (custom-set-variables + ;; https://github.com/purcell/emacs.d/issues/778 + '(completion-styles '(basic completion-partial orderless)) + '(completion-category-defaults nil) + '(completion-category-overrides + '((file (styles partial-completion))))) + (add-hook 'minibuffer-setup-hook + (defun my-on-minibuffer-setup-hook() + (setq-default completion-styles '(substring orderless))))) #+end_src ** [[info:embark#Top][Embark (info)]] @@ -787,12 +790,11 @@ minibuffer help after a prefix key. #+caption: Configure =embark=. #+name: lst:configure-embark #+begin_src emacs-lisp - (unless noninteractive - (when (cl-every #'fboundp '(embark-act embark-bindings embark-dwim)) - (global-set-key (kbd "C-,") #'embark-act) - (global-set-key (kbd "C-:") #'embark-dwim) - (global-set-key (kbd "C-h B") #'embark-bindings) - (setq prefix-help-command #'embark-prefix-help-command))) + (when (cl-every #'fboundp '(embark-act embark-bindings embark-dwim)) + (global-set-key (kbd "C-,") #'embark-act) + (global-set-key (kbd "C-:") #'embark-dwim) + (global-set-key (kbd "C-h B") #'embark-bindings) + (setq prefix-help-command #'embark-prefix-help-command)) #+end_src ** [[info:marginalia#Top][Marginalia (info)]] @@ -806,9 +808,8 @@ Listing [[lst:enable-marginalia-mode]] enables =marginalia-mode=. #+caption: Enable =marginalia-mode=. #+name: lst:enable-marginalia-mode #+begin_src emacs-lisp - (unless noninteractive - (when (fboundp 'marginalia-mode) - (marginalia-mode +1))) + (when (fboundp 'marginalia-mode) + (marginalia-mode +1)) #+end_src ** [[info:consult#Top][Consult (info)]] @@ -870,41 +871,40 @@ Listing [[lst:configure-consult]] configures =consult=. #+caption: Configure =consult=. #+name: lst:configure-consult #+begin_src emacs-lisp - (unless noninteractive - (when (fboundp 'consult-apropos) - (custom-set-variables - '(consult-project-root-function #'vc-root-dir)) - ;; C-c bindings (mode-specific-map) - (global-set-key (kbd "C-c h") #'consult-history) - (global-set-key (kbd "C-c m") #'consult-mode-command) - ;; C-x bindings (ctl-x-map) - (define-key ctl-x-map (kbd "M-:") #'consult-complex-command) - (define-key ctl-x-map (kbd "b") #'consult-buffer) - (define-key ctl-x-map (kbd "4 b") #'consult-buffer-other-window) - (define-key ctl-x-map (kbd "5 b") #'consult-buffer-other-frame) - (define-key ctl-x-map (kbd "r x") #'consult-register) - (define-key ctl-x-map (kbd "r b") #'consult-bookmark) - ;; M-g bindings (goto-map) - (define-key goto-map (kbd "g") #'consult-goto-line) - (define-key goto-map (kbd "M-g") #'consult-goto-line) - (define-key goto-map (kbd "o") #'consult-outline) - (define-key goto-map (kbd "m") #'consult-mark) - (define-key goto-map (kbd "k") #'consult-global-mark) - (define-key goto-map (kbd "i") #'consult-imenu-project) - (define-key goto-map (kbd "e") #'consult-compile-error) - ;; M-s bindings (search-map) - (define-key search-map (kbd "g") #'consult-git-grep) - (define-key search-map (kbd "f") #'consult-find) - (define-key search-map (kbd "k") #'consult-keep-lines) - (define-key search-map (kbd "l") #'consult-line) - (define-key search-map (kbd "m") #'consult-multi-occur) - (define-key search-map (kbd "u") #'consult-focus-lines) - ;; Other bindings - (global-set-key (kbd "M-y") #'consult-yank-pop) - (global-set-key (kbd " a") #'consult-apropos) - ;; Tweak functions - (advice-add 'completing-read-multiple - :override #'consult-completing-read-multiple))) + (when (fboundp 'consult-apropos) + (custom-set-variables + '(consult-project-root-function #'vc-root-dir)) + ;; C-c bindings (mode-specific-map) + (global-set-key (kbd "C-c h") #'consult-history) + (global-set-key (kbd "C-c m") #'consult-mode-command) + ;; C-x bindings (ctl-x-map) + (define-key ctl-x-map (kbd "M-:") #'consult-complex-command) + (define-key ctl-x-map (kbd "b") #'consult-buffer) + (define-key ctl-x-map (kbd "4 b") #'consult-buffer-other-window) + (define-key ctl-x-map (kbd "5 b") #'consult-buffer-other-frame) + (define-key ctl-x-map (kbd "r x") #'consult-register) + (define-key ctl-x-map (kbd "r b") #'consult-bookmark) + ;; M-g bindings (goto-map) + (define-key goto-map (kbd "g") #'consult-goto-line) + (define-key goto-map (kbd "M-g") #'consult-goto-line) + (define-key goto-map (kbd "o") #'consult-outline) + (define-key goto-map (kbd "m") #'consult-mark) + (define-key goto-map (kbd "k") #'consult-global-mark) + (define-key goto-map (kbd "i") #'consult-imenu-project) + (define-key goto-map (kbd "e") #'consult-compile-error) + ;; M-s bindings (search-map) + (define-key search-map (kbd "g") #'consult-git-grep) + (define-key search-map (kbd "f") #'consult-find) + (define-key search-map (kbd "k") #'consult-keep-lines) + (define-key search-map (kbd "l") #'consult-line) + (define-key search-map (kbd "m") #'consult-multi-occur) + (define-key search-map (kbd "u") #'consult-focus-lines) + ;; Other bindings + (global-set-key (kbd "M-y") #'consult-yank-pop) + (global-set-key (kbd " a") #'consult-apropos) + ;; Tweak functions + (advice-add 'completing-read-multiple + :override #'consult-completing-read-multiple)) #+end_src ** [[https://company-mode.github.io/][Company: a modular complete anything framework for Emacs]] @@ -918,20 +918,19 @@ Listing [[lst:configure-company]] configures =company=. #+caption: Configure =company=. #+name: lst:configure-company #+begin_src emacs-lisp - (unless noninteractive - (when (fboundp 'company-mode) - (custom-set-variables - ;; https://github.com/purcell/emacs.d/issues/778 - '(company-transformers '(company-sort-by-occurrence))) - (dolist (hook '(LaTeX-mode-hook - org-mode-hook - emacs-lisp-mode-hook - lisp-interaction-mode-hook - lisp-mode-hook - python-mode-hook - ielm-mode-hook - sly-mrepl-mode-hook)) - (add-hook hook #'company-mode)))) + (when (fboundp 'company-mode) + (custom-set-variables + ;; https://github.com/purcell/emacs.d/issues/778 + '(company-transformers '(company-sort-by-occurrence))) + (dolist (hook '(LaTeX-mode-hook + org-mode-hook + emacs-lisp-mode-hook + lisp-interaction-mode-hook + lisp-mode-hook + python-mode-hook + ielm-mode-hook + sly-mrepl-mode-hook)) + (add-hook hook #'company-mode))) #+end_src ** [[https://lists.gnu.org/archive/html/emacs-devel/2021-12/msg00802.html][Minibuffer history completion]] @@ -947,30 +946,31 @@ previous input in the minibuffer. Listing #+caption: Enable =minibuffer-history-completion=. #+name: lst:enable-minibuffer-history-completion #+begin_src emacs-lisp - (defun minibuffer-setup-history-completions () - (unless (or minibuffer-completion-table minibuffer-completion-predicate) - (setq-local minibuffer-completion-table - (symbol-value minibuffer-history-variable)))) + (with-eval-after-load 'emacs + (defun minibuffer-setup-history-completions () + (unless (or minibuffer-completion-table minibuffer-completion-predicate) + (setq-local minibuffer-completion-table + (symbol-value minibuffer-history-variable)))) - (add-hook 'minibuffer-setup-hook 'minibuffer-setup-history-completions) + (add-hook 'minibuffer-setup-hook 'minibuffer-setup-history-completions) - ;; Stolen from Emacs-28.1 for Emacs-27.2: - (unless (fboundp 'minibuffer--completion-prompt-end) - (defun minibuffer--completion-prompt-end () - (let ((end (minibuffer-prompt-end))) - (if (< (point) end) - (user-error "Can't complete in prompt") - end)))) + ;; Stolen from Emacs-28.1 for Emacs-27.2: + (unless (fboundp 'minibuffer--completion-prompt-end) + (defun minibuffer--completion-prompt-end () + (let ((end (minibuffer-prompt-end))) + (if (< (point) end) + (user-error "Can't complete in prompt") + end)))) - ;; Adapted from ‘minibuffer-complete’: - (defun minibuffer-complete-history () - "Allow minibuffer completion on previous input." - (interactive) - (completion-in-region (minibuffer--completion-prompt-end) (point-max) - (symbol-value minibuffer-history-variable) - nil)) + ;; Adapted from ‘minibuffer-complete’: + (defun minibuffer-complete-history () + "Allow minibuffer completion on previous input." + (interactive) + (completion-in-region (minibuffer--completion-prompt-end) (point-max) + (symbol-value minibuffer-history-variable) + nil)) - (define-key minibuffer-local-map (kbd "C-") #'minibuffer-complete-history) + (define-key minibuffer-local-map (kbd "C-") #'minibuffer-complete-history)) #+end_src * [[info:emacs#Search][Search and replace (info)]] @@ -984,8 +984,8 @@ previous input in the minibuffer. Listing :END: [[https://github.com/Wilfred/deadgrep#readme][Deadgrep]] uses [[https://github.com/BurntSushi/ripgrep#readme][ripgrep]] for superfast text searching in the default directory or -the current [[https://en.wikipedia.org/wiki/Version_control][VCS]] directory tree. Listing [[lst:configure-deadgrep]] binds the -=deadgrep= function to {{{kbd(M-s d)}}}. +the current [[https://en.wikipedia.org/wiki/Version_control][VCS]] directory tree. Listing [[lst:configure-deadgrep]] binds =deadgrep= +to {{{kbd(M-s d)}}} and =deadgrep-edit-mode= to {{{kbd(C-c C-w)}}}. #+caption[Configure =deadgrep=]: #+caption: Configure =deadgrep=. @@ -993,6 +993,8 @@ the current [[https://en.wikipedia.org/wiki/Version_control][VCS]] directory tre #+begin_src emacs-lisp (when (autoload 'deadgrep "deadgrep" nil t) (define-key search-map (kbd "d") #'deadgrep)) + (with-eval-after-load 'deadgrep + (define-key deadgrep-mode-map (kbd "C-c C-w") #'deadgrep-edit-mode)) #+end_src * Reading @@ -1042,17 +1044,17 @@ rebuild the =epdfinfo= executable that serves the [[https://en.wikipedia.org/wik #+caption: Enable =pdf-tools=. #+name: lst:enable-pdf-tools #+begin_src emacs-lisp - ;; `pdf-loader-install' is the lazy equivalent of `pdf-tools-install': - ;; see the README file. (when (fboundp 'pdf-loader-install) - (pdf-loader-install)) + ;; `pdf-loader-install' is the lazy equivalent of `pdf-tools-install': + ;; see the README file. + (pdf-loader-install) - (with-eval-after-load 'pdf-view - (custom-set-variables - '(pdf-view-display-size 'fit-page)) + (with-eval-after-load 'pdf-view + (custom-set-variables + '(pdf-view-display-size 'fit-page)) - (when (fboundp 'pdf-view-restore-mode) - (add-hook 'pdf-view-mode-hook #'pdf-view-restore-mode))) + (when (fboundp 'pdf-view-restore-mode) + (add-hook 'pdf-view-mode-hook #'pdf-view-restore-mode)))) #+end_src * Writing @@ -1206,15 +1208,14 @@ advising to override ~TeX-brace-count-line~ with ~my-TeX-brace-count-line~. #+caption: Activate =Org=. #+name: lst:activate-org #+begin_src emacs-lisp - ;; Inspect: - ;; function with "C-h f" - ;; symbols with "C-h o" - ;; variables with "C-h v" - - (global-set-key (kbd "C-c a") #'org-agenda) - (global-set-key (kbd "C-c c") #'org-capture) - (global-set-key (kbd "C-c l") #'org-store-link) - (global-set-key (kbd "C-c C-l") #'org-insert-link-global) + (when (cl-every #'fboundp '(org-agenda + org-capture + org-store-link + org-store-link-global)) + (global-set-key (kbd "C-c a") #'org-agenda) + (global-set-key (kbd "C-c c") #'org-capture) + (global-set-key (kbd "C-c l") #'org-store-link) + (global-set-key (kbd "C-c C-l") #'org-insert-link-global)) #+end_src *** Org customization @@ -1517,8 +1518,10 @@ compatibility with [[https://github.com/jkitchin/org-ref][org-ref]]. Listing [[ from the definition of =docview-org-link= and =doi-org-link= types to define an =pdfview-org-link= type for use with [[https://github.com/vedang/pdf-tools][pdf-tools]]. Finally, listing [[lst:emacs-lisp-setup-patch-ol-info]] patches the function =org-info-export= and -the constant ~org-info-other-documents~, to export the =info-org-link= types in -this document to =html= and LaTeX correctly. +listing [[lst:emacs-lisp-setup-buffer-local-ol-info]] sets the constants +~org-info-emacs-documents~ and ~org-info-other-documents~ as buffer local +variables in order to export the =info-org-link= types in this document to +=html= and LaTeX correctly. #+caption[Define =org-link= types for backwards compatibility with =org-ref=]: #+caption: Define =org-link= types for backwards compatibility with =org-ref=. @@ -1632,8 +1635,14 @@ this document to =html= and LaTeX correctly. (`texinfo (let ((title (or desc ""))) (format "@ref{%s,%s,,%s,}" node title manual))) - (_ nil)))) + (_ nil))))) +#+end_src +#+caption[Patch buffer local =ol-info=]: +#+caption: Patch buffer local =ol-info=. +#+name: lst:emacs-lisp-setup-buffer-local-ol-info +#+begin_src emacs-lisp :exports code :silent :tangle no + (with-eval-after-load 'ol-info (make-variable-buffer-local 'org-info-emacs-documents) (setq org-info-emacs-documents (delete "org" org-info-emacs-documents)) (make-variable-buffer-local 'org-info-other-documents) @@ -1645,10 +1654,8 @@ this document to =html= and LaTeX correctly. ("orderless" . "https://github.com/oantolin/orderless") ("sly" . "https://joaotavora.github.io/sly/") ("vertico" . "https://github.com/minad/vertico")) - org-info-other-documents - :test #'equal))) + org-info-other-documents :test #'equal))) #+end_src - *** [[https://tecosaur.github.io/emacs-config/#translate-capital-keywords][Translate capital keywords (old) to lower case (new)]] :PROPERTIES: :CUSTOM_ID: sec:convert-upper-to-lower-case-keywords @@ -2087,7 +2094,7 @@ exporting from Org-mode to LaTeX. #+caption: Define buffer local =-ox-latex= variables. #+header: :var title-page=lst/title-page #+name: lst:ox-latex-emacs-lisp-setup -#+begin_src emacs-lisp :results silent +#+begin_src emacs-lisp :results silent :tangle no (when (require 'ox-latex nil 'noerror) ;; https://emacs.stackexchange.com/questions/47347/ ;; customizing-org-latex-title-command-to-edit-title-page @@ -2879,7 +2886,7 @@ library. It is a requirement of several packages in this Emacs setup ([[https:/ #+caption: Enable =iedit=. #+name: lst:enable-iedit #+begin_src emacs-lisp - (unless noninteractive + (with-eval-after-load 'emacs (require 'iedit nil 'noerror)) #+end_src @@ -2892,12 +2899,11 @@ library. It is a requirement of several packages in this Emacs setup ([[https:/ #+caption: Configure =ws-butler=. #+name: lst:configure-ws-butler #+begin_src emacs-lisp - (unless noninteractive - (when (require 'ws-butler nil 'noerror) - (custom-set-variables - '(ws-butler-keep-whitespace-before-point nil)) - (add-hook 'prog-mode-hook #'ws-butler-mode) - (add-hook 'text-mode-hook #'ws-butler-mode))) + (when (require 'ws-butler nil 'noerror) + (custom-set-variables + '(ws-butler-keep-whitespace-before-point nil)) + (add-hook 'prog-mode-hook #'ws-butler-mode) + (add-hook 'text-mode-hook #'ws-butler-mode)) #+end_src ** [[https://countvajhula.com/2021/09/25/the-animated-guide-to-symex/][Structural editing]] @@ -2944,7 +2950,7 @@ contrary to for instance [[https://github.com/Fanael/rainbow-delimiters#readme][ #+caption: Configure =smartparens=. #+name: lst:configure-smartparens #+begin_src emacs-lisp - (unless noninteractive + (with-eval-after-load 'emacs ;; To disables pairing of the quote character for lisp modes, ;; require smartparens-config instead of smartparens. (when (require 'smartparens-config nil 'noerror) @@ -3098,7 +3104,7 @@ of the default face on all frames. #+caption: Configure =face-attributes=. #+name: lst:configure-face-attributes #+begin_src emacs-lisp - (unless noninteractive + (with-eval-after-load 'emacs ;; Set face attributes. (cond ((eq system-type 'darwin) @@ -3119,7 +3125,7 @@ of the default face on all frames. #+caption: Implement =my-set-default-face-height=. #+name: lst:my-set-default-face-height #+begin_src emacs-lisp - (unless noninteractive + (with-eval-after-load 'emacs (defun my-set-default-face-height () "Set the default face height in all current and future frames. @@ -3139,7 +3145,7 @@ of the default face on all frames. #+caption: Implement =my-invert-default-face=. #+name: lst:my-invert-default-face #+begin_src emacs-lisp - (unless noninteractive + (with-eval-after-load 'emacs (defun my-invert-default-face () "Invert the default face." (interactive) @@ -3182,7 +3188,7 @@ and names in buffers for debugging. #+caption: Implement =my-pulse-one-line=. #+name: lst:my-pulse-one-line #+begin_src emacs-lisp - (unless noninteractive + (with-eval-after-load 'emacs ;; https://karthinks.com/software/batteries-included-with-emacs/ ;; https://www.reddit.com/r/emacs/comments/jwhr6g/batteries_included_with_emacs/ (defun my-pulse-one-line (&rest _)