Compare commits

...

4 Commits

View File

@ -4977,12 +4977,9 @@ Links for further investigation are:
#+name: lst:setup-go
#+begin_src emacs-lisp -n :results silent
(when (featurep 'treesit)
;; Set `tab-width' in `after-change-major-mode-hook' function too.
(setopt go-ts-mode-indent-offset 2)
(add-hook 'after-change-major-mode-hook
(defun on-go-ts-mode-hook ()
(when (derived-mode-p 'go-ts-mode 'go-mod-ts-mode)
(setq-local tab-width 2))))
(add-hook 'go-ts-mode-hook (lambda ()
(setq-local tab-width 2)))
(add-to-list 'auto-mode-alist `(,(rx ".go" eos) . go-ts-mode)))
#+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
how the machinery after the first and after later usages of =eval-expression=
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,
Lisp dialects, Org, and Python. Execute src_emacs-lisp[:results
Listing [[lst:setup-smartparens]] aims to setup [[https://github.com/Fuco1/smartparens][smartparens]] for Go, LaTeX, Lisp
dialects, Org, and Python. Execute src_emacs-lisp[:results
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
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?"]],
[[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,
contrary to for instance [[https://github.com/Fanael/rainbow-delimiters#readme][rainbow-delimiters]].
#+caption[Configure =smartparens=]:
#+caption: Configure =smartparens=.
#+name: lst:configure-smartparens
#+caption[Setup =smartparens=]:
#+caption: Setup =smartparens=.
#+name: lst:setup-smartparens
#+begin_src emacs-lisp -n :results silent
(when (and (ensure-package-installation 'smartparens)
;; Require `smartparens-config' instead of `smartparens' to
;; disable pairing of the quote character for lisp modes.
(require 'smartparens-config nil 'noerror))
(when (ensure-package-installation 'smartparens)
;; GAV: Documentation says to require `smartparens-config'.
(require 'smartparens-config)
(setopt sp-base-key-bindings 'sp
sp-override-key-bindings '(("C-(" . sp-backward-slurp-sexp)
("C-)" . sp-forward-slurp-sexp)
("C-M-(" . sp-backward-barf-sexp)
("C-M-)" . sp-forward-barf-sexp)))
(when (fboundp 'smartparens-mode)
(dolist (symbol '(conf-toml-mode-hook prog-mode-hook text-mode-hook))
(add-hook symbol #'smartparens-mode)))
(add-hook 'conf-toml-mode-hook #'smartparens-mode)
(add-hook 'prog-mode-hook #'smartparens-mode)
(add-hook 'text-mode-hook #'smartparens-mode)
(when (fboundp 'smartparens-strict-mode)
(dolist (symbol '(emacs-lisp-mode-hook
go-ts-mode-hook
ielm-mode-hook
inferior-python-mode-hook
lisp-data-mode-hook
lisp-mode-hook
python-mode-hook
sly-mrepl-mode-hook))
(add-hook symbol #'smartparens-strict-mode)))
(add-hook 'emacs-lisp-mode-hook #'smartparens-strict-mode)
(add-hook 'go-ts-mode-hook #'smartparens-strict-mode)
(add-hook 'ielm-mode-hook #'smartparens-strict-mode)
(add-hook 'inferior-python-mode-hook #'smartparens-strict-mode)
(add-hook 'lisp-data-mode-hook #'smartparens-strict-mode)
(add-hook 'lisp-mode-hook #'smartparens-strict-mode)
(add-hook 'python-mode-hook #'smartparens-strict-mode)
(add-hook 'sly-mrepl-mode-hook #'smartparens-strict-mode)
(when (fboundp 'go-ts-mode)
;; 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)}}} | |
|--------------------------------+----------------------------+----------|
#+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]]
:PROPERTIES:
@ -5756,19 +5780,16 @@ formatter for Python]].
:CUSTOM_ID: sec:smart-snippets
:END:
#+caption[Enable =yas-global-mode=]:
#+caption: Enable =yas-global-mode=.
#+name: lst:enable-yas-global-mode
#+caption[Setup =yasnippet=]:
#+caption: Setup =yasnippet=.
#+name: lst:setup-yasnippet
#+begin_src emacs-lisp -n :results silent
(when (ensure-package-installation 'yasnippet)
;; Set `yas-alias-to-yas/prefix-p' before loading `yasnippet'.
(setopt yas-alias-to-yas/prefix-p nil)
(when (fboundp 'yas-minor-mode)
(dolist (symbol '(LaTeX-mode-hook
org-mode-hook
python-mode-hook
python-ts-mode-hook))
(add-hook symbol #'yas-minor-mode))))
(add-hook 'LaTeX-mode-hook #'yas-minor-mode)
(add-hook 'org-mode-hook #'yas-minor-mode)
(add-hook 'python-mode-hook #'yas-minor-mode))
#+end_src
* [[info:emacs#Display][Display (info)]]
@ -5848,12 +5869,11 @@ and names in buffers for debugging.
#+name: lst:setup-rainbow-mode
#+begin_src emacs-lisp -n :results silent
(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
(list 'c++-mode 'c-mode 'emacs-lisp-mode 'inferior-emacs-lisp-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)))
'lisp-interaction-mode 'org-mode 'python-mode)))
#+end_src
** [[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-momentary-highlight-one-line (point))))
(dolist (command '(scroll-up-command
scroll-down-command
recenter-top-bottom
other-window))
(advice-add command :after #'flash-line-around-point))
(advice-add 'scroll-up-command :after #'flash-line-around-point)
(advice-add 'scroll-down-command :after #'flash-line-around-point)
(advice-add 'recenter-top-bottom :after #'flash-line-around-point)
(advice-add 'other-window :after #'flash-line-around-point)
#+end_src
* Applications