Compare commits

..

4 Commits

View File

@ -4977,12 +4977,9 @@ Links for further investigation are:
#+name: lst:setup-go #+name: lst:setup-go
#+begin_src emacs-lisp -n :results silent #+begin_src emacs-lisp -n :results silent
(when (featurep 'treesit) (when (featurep 'treesit)
;; Set `tab-width' in `after-change-major-mode-hook' function too.
(setopt go-ts-mode-indent-offset 2) (setopt go-ts-mode-indent-offset 2)
(add-hook 'after-change-major-mode-hook (add-hook 'go-ts-mode-hook (lambda ()
(defun on-go-ts-mode-hook () (setq-local tab-width 2)))
(when (derived-mode-p 'go-ts-mode 'go-mod-ts-mode)
(setq-local tab-width 2))))
(add-to-list 'auto-mode-alist `(,(rx ".go" eos) . go-ts-mode))) (add-to-list 'auto-mode-alist `(,(rx ".go" eos) . go-ts-mode)))
#+end_src #+end_src
@ -5627,13 +5624,15 @@ following links show how to put the documentation to practical use:
3. [[https://lists.gnu.org/archive/html/help-gnu-emacs/2014-07/msg00135.html][How to enable smartparens in the minibuffer after eval-expression]] explains 3. [[https://lists.gnu.org/archive/html/help-gnu-emacs/2014-07/msg00135.html][How to enable smartparens in the minibuffer after eval-expression]] explains
how the machinery after the first and after later usages of =eval-expression= how the machinery after the first and after later usages of =eval-expression=
differ and discusses options how to handle those differences. differ and discusses options how to handle those differences.
Listing [[lst:configure-smartparens]] aims to configure [[https://github.com/Fuco1/smartparens][smartparens]] for Go, LaTeX, Listing [[lst:setup-smartparens]] aims to setup [[https://github.com/Fuco1/smartparens][smartparens]] for Go, LaTeX, Lisp
Lisp dialects, Org, and Python. Execute src_emacs-lisp[:results dialects, Org, and Python. Execute src_emacs-lisp[:results
none]{(sp-cheat-sheet)} for short documentation taking into account the none]{(sp-cheat-sheet)} for short documentation taking into account the
overridden key bindings in listing [[lst:configure-smartparens]]. Table overridden key bindings in listing [[lst:setup-smartparens]]. Table
[[tab:smartparens-commands-and-bindings]] lists commands with key bindings taken in [[tab:smartparens-commands-and-bindings]] lists commands with key bindings taken in
order from src_emacs-lisp[:results none]{(sp-cheat-sheet)} that takes the order from src_emacs-lisp[:results none]{(sp-cheat-sheet)} that takes the
overrides of listing [[lst:configure-smartparens]] into account. overrides of listing [[lst:setup-smartparens]] into account. Finally, listing
[[lst:sp-eval-expression]] defines an alternative to =eval-expression= enabling
=smartparens-strict-mode= and =font-lock-mode=.
Despite the provocative post [[https://andreyorst.gitlab.io/posts/2022-02-20-what-if-structural-editing-was-a-mistake/]["What if structural editing was a mistake?"]], Despite the provocative post [[https://andreyorst.gitlab.io/posts/2022-02-20-what-if-structural-editing-was-a-mistake/]["What if structural editing was a mistake?"]],
[[https://github.com/Fuco1/smartparens][smartparens]] is one of my favorite packages. In particular, [[https://github.com/Fuco1/smartparens][smartparens]] handles [[https://github.com/Fuco1/smartparens][smartparens]] is one of my favorite packages. In particular, [[https://github.com/Fuco1/smartparens][smartparens]] handles
@ -5643,34 +5642,31 @@ inside source blocks) correctly. Therefore, [[https://smartparens.readthedocs.i
matching pairs immediately in front or after point in such files correctly, matching pairs immediately in front or after point in such files correctly,
contrary to for instance [[https://github.com/Fanael/rainbow-delimiters#readme][rainbow-delimiters]]. contrary to for instance [[https://github.com/Fanael/rainbow-delimiters#readme][rainbow-delimiters]].
#+caption[Configure =smartparens=]: #+caption[Setup =smartparens=]:
#+caption: Configure =smartparens=. #+caption: Setup =smartparens=.
#+name: lst:configure-smartparens #+name: lst:setup-smartparens
#+begin_src emacs-lisp -n :results silent #+begin_src emacs-lisp -n :results silent
(when (and (ensure-package-installation 'smartparens) (when (ensure-package-installation 'smartparens)
;; Require `smartparens-config' instead of `smartparens' to ;; GAV: Documentation says to require `smartparens-config'.
;; disable pairing of the quote character for lisp modes. (require 'smartparens-config)
(require 'smartparens-config nil 'noerror))
(setopt sp-base-key-bindings 'sp (setopt sp-base-key-bindings 'sp
sp-override-key-bindings '(("C-(" . sp-backward-slurp-sexp) sp-override-key-bindings '(("C-(" . sp-backward-slurp-sexp)
("C-)" . sp-forward-slurp-sexp) ("C-)" . sp-forward-slurp-sexp)
("C-M-(" . sp-backward-barf-sexp) ("C-M-(" . sp-backward-barf-sexp)
("C-M-)" . sp-forward-barf-sexp))) ("C-M-)" . sp-forward-barf-sexp)))
(when (fboundp 'smartparens-mode) (add-hook 'conf-toml-mode-hook #'smartparens-mode)
(dolist (symbol '(conf-toml-mode-hook prog-mode-hook text-mode-hook)) (add-hook 'prog-mode-hook #'smartparens-mode)
(add-hook symbol #'smartparens-mode))) (add-hook 'text-mode-hook #'smartparens-mode)
(when (fboundp 'smartparens-strict-mode) (add-hook 'emacs-lisp-mode-hook #'smartparens-strict-mode)
(dolist (symbol '(emacs-lisp-mode-hook (add-hook 'go-ts-mode-hook #'smartparens-strict-mode)
go-ts-mode-hook (add-hook 'ielm-mode-hook #'smartparens-strict-mode)
ielm-mode-hook (add-hook 'inferior-python-mode-hook #'smartparens-strict-mode)
inferior-python-mode-hook (add-hook 'lisp-data-mode-hook #'smartparens-strict-mode)
lisp-data-mode-hook (add-hook 'lisp-mode-hook #'smartparens-strict-mode)
lisp-mode-hook (add-hook 'python-mode-hook #'smartparens-strict-mode)
python-mode-hook (add-hook 'sly-mrepl-mode-hook #'smartparens-strict-mode)
sly-mrepl-mode-hook))
(add-hook symbol #'smartparens-strict-mode)))
(when (fboundp 'go-ts-mode) (when (fboundp 'go-ts-mode)
;; Stolen from `smartparens-go': ;; Stolen from `smartparens-go':
@ -5731,6 +5727,34 @@ contrary to for instance [[https://github.com/Fanael/rainbow-delimiters#readme][
| sp-mark-sexp | {{{kbd(C-M-SPC)}}} | | | sp-mark-sexp | {{{kbd(C-M-SPC)}}} | |
|--------------------------------+----------------------------+----------| |--------------------------------+----------------------------+----------|
#+caption[Define =sp-eval-expression= with =smartparens= support]:
#+caption: Define =sp-eval-expression= enabling =smartparens-strict-mode=
#+caption: and =font-lock-mode=.
#+name: lst:sp-eval-expression
#+begin_src emacs-lisp -n :results silent
(with-eval-after-load 'smartparens
;; https://lists.gnu.org/archive/html/help-gnu-emacs/2014-07/msg00135.html
;; GAV: Reuse `read--expresssion-map' instead of defining my own map.
(defun sp--read-expression (prompt &optional initial-contents)
(let ((minibuffer-completing-symbol t))
(minibuffer-with-setup-hook
(lambda ()
(emacs-lisp-mode) ; Enables `smartparens-strict-mode' too.
(use-local-map read--expression-map)
(font-lock-mode t))
(read-from-minibuffer prompt initial-contents
read--expression-map nil
'read-expression-history))))
(defun sp-eval-expression (expression &optional arg)
"Evaluate EXPRESSION with `smartparens' support."
(interactive (list (read (sp--read-expression "SP eval: "))
current-prefix-arg))
(if arg
(insert (pp-to-string (eval expression lexical-binding)))
(pp-display-expression (eval expression lexical-binding)
"*SP Eval Output*"))))
#+end_src
** [[https://github.com/davidshepherd7/electric-operator#readme][Electric operators]] ** [[https://github.com/davidshepherd7/electric-operator#readme][Electric operators]]
:PROPERTIES: :PROPERTIES:
@ -5756,19 +5780,16 @@ formatter for Python]].
:CUSTOM_ID: sec:smart-snippets :CUSTOM_ID: sec:smart-snippets
:END: :END:
#+caption[Enable =yas-global-mode=]: #+caption[Setup =yasnippet=]:
#+caption: Enable =yas-global-mode=. #+caption: Setup =yasnippet=.
#+name: lst:enable-yas-global-mode #+name: lst:setup-yasnippet
#+begin_src emacs-lisp -n :results silent #+begin_src emacs-lisp -n :results silent
(when (ensure-package-installation 'yasnippet) (when (ensure-package-installation 'yasnippet)
;; Set `yas-alias-to-yas/prefix-p' before loading `yasnippet'. ;; Set `yas-alias-to-yas/prefix-p' before loading `yasnippet'.
(setopt yas-alias-to-yas/prefix-p nil) (setopt yas-alias-to-yas/prefix-p nil)
(when (fboundp 'yas-minor-mode) (add-hook 'LaTeX-mode-hook #'yas-minor-mode)
(dolist (symbol '(LaTeX-mode-hook (add-hook 'org-mode-hook #'yas-minor-mode)
org-mode-hook (add-hook 'python-mode-hook #'yas-minor-mode))
python-mode-hook
python-ts-mode-hook))
(add-hook symbol #'yas-minor-mode))))
#+end_src #+end_src
* [[info:emacs#Display][Display (info)]] * [[info:emacs#Display][Display (info)]]
@ -5848,12 +5869,11 @@ and names in buffers for debugging.
#+name: lst:setup-rainbow-mode #+name: lst:setup-rainbow-mode
#+begin_src emacs-lisp -n :results silent #+begin_src emacs-lisp -n :results silent
(when (ensure-package-installation 'rainbow-mode) (when (ensure-package-installation 'rainbow-mode)
;; GAV: Do not add `rainbow-mode' to any programming language hook,
;; since that interferes at least with Org export to LaTeX.
(setopt rainbow-x-colors-major-mode-list (setopt rainbow-x-colors-major-mode-list
(list 'c++-mode 'c-mode 'emacs-lisp-mode 'inferior-emacs-lisp-mode (list 'c++-mode 'c-mode 'emacs-lisp-mode 'inferior-emacs-lisp-mode
'lisp-interaction-mode 'org-mode 'python-mode)) 'lisp-interaction-mode 'org-mode 'python-mode)))
;; GAV: How to disable `rainbow-mode' on `emacs-lisp-mode-hook'?
(dolist (symbol '(python-mode-hook))
(add-hook symbol #'rainbow-mode)))
#+end_src #+end_src
** [[https://karthinks.com/software/batteries-included-with-emacs/][Flash the line around point for visual feedback]] ** [[https://karthinks.com/software/batteries-included-with-emacs/][Flash the line around point for visual feedback]]
@ -5881,11 +5901,10 @@ point movements visually.
(pulse-delay 0.1)) (pulse-delay 0.1))
(pulse-momentary-highlight-one-line (point)))) (pulse-momentary-highlight-one-line (point))))
(dolist (command '(scroll-up-command (advice-add 'scroll-up-command :after #'flash-line-around-point)
scroll-down-command (advice-add 'scroll-down-command :after #'flash-line-around-point)
recenter-top-bottom (advice-add 'recenter-top-bottom :after #'flash-line-around-point)
other-window)) (advice-add 'other-window :after #'flash-line-around-point)
(advice-add command :after #'flash-line-around-point))
#+end_src #+end_src
* Applications * Applications