docs(emacs): remove csetq, replace it with setopt
All checks were successful
deploy / build (push) Successful in 5m24s

This commit is contained in:
Lucien Cartier-Tilet 2024-10-06 11:58:42 +02:00
parent 4baaaadf02
commit d9a7e58f1e
Signed by: phundrak
GPG Key ID: 347803E8073EACE0
5 changed files with 49 additions and 93 deletions

View File

@ -350,47 +350,3 @@ on the matter.
(unless (string= "-" project-name) (unless (string= "-" project-name)
(format (if (buffer-modified-p) " ◉ %s" "  ●  %s - Emacs") project-name)))))) (format (if (buffer-modified-p) " ◉ %s" "  ●  %s - Emacs") project-name))))))
#+end_src #+end_src
** A better custom variable setter
Something people often forget about custom variables in Elisp is they
can have a custom setter that will run some code if we set the
variable properly with ~customize-set-variable~, so ~setq~ shouldnt be
the users choice by default. But repeatedly writing
~customize-set-variable~ can get tiring and boring. So why not take the
best of both world and create ~csetq~, a ~setq~ that uses
~customize-set-variable~ under the hood while it keeps a syntax similar
to the one ~setq~ uses?
#+begin_src emacs-lisp
(defmacro csetq (&rest forms)
"Bind each custom variable FORM to the value of its VAL.
FORMS is a list of pairs of values [FORM VAL].
`customize-set-variable' is called sequentially on each pair
contained in FORMS. This means `csetq' has a similar behaviour as
`setq': each VAL expression is evaluated sequentially, i.e. the
first VAL is evaluated before the second, and so on. This means
the value of the first FORM can be used to set the second FORM.
The return value of `csetq' is the value of the last VAL.
\(fn [FORM VAL]...)"
(declare (debug (&rest sexp form))
(indent 1))
;; Check if we have an even number of arguments
(when (= (mod (length forms) 2) 1)
(signal 'wrong-number-of-arguments (list 'csetq (1+ (length forms)))))
;; Transform FORMS into a list of pairs (FORM . VALUE)
(let (sexps)
(while forms
(let ((form (pop forms))
(value (pop forms)))
(push `(customize-set-variable ',form ,value)
sexps)))
`(progn ,@(nreverse sexps))))
#+end_src
I first got inspired by [[https://oremacs.com/2015/01/17/setting-up-ediff/][this blog article]] (archived article, just in
case) but it seems the code snippet no longer works properly, so not
only did I have to modify it to make it work with an arbitrary amount
of arguments (as long as its pairs of variables and their value), but
I also had to make the code simply work.

View File

@ -409,13 +409,13 @@ configuration for the ~mu4e~ package itself.
<<mu4e-ical-setup>> <<mu4e-ical-setup>>
<<mu4e-ical-init-config>> <<mu4e-ical-init-config>>
(csetq mu4e-completing-read-function 'completing-read (setopt mu4e-completing-read-function 'completing-read
mu4e-use-fancy-chars t mu4e-use-fancy-chars t
message-kill-buffer-on-exit t message-kill-buffer-on-exit t
mu4e-org-support nil) mu4e-org-support nil)
(let ((dir (concat (getenv "HOME") "/Downloads/mu4e"))) (let ((dir (concat (getenv "HOME") "/Downloads/mu4e")))
(when (file-directory-p dir) (when (file-directory-p dir)
(csetq mu4e-attachment-dir dir))) (setopt mu4e-attachment-dir dir)))
(defmacro mu4e-view-mode--prepare () (defmacro mu4e-view-mode--prepare ()
`(lambda () (visual-line-mode 1))) `(lambda () (visual-line-mode 1)))
:gfhook ('mu4e-view-mode-hook (mu4e-view-mode--prepare)) :gfhook ('mu4e-view-mode-hook (mu4e-view-mode--prepare))
@ -1331,7 +1331,7 @@ dark mode for PDFs.
"m" 'pdf-view-midnight-minor-mode) "m" 'pdf-view-midnight-minor-mode)
:config :config
(with-eval-after-load 'pdf-view (with-eval-after-load 'pdf-view
(csetq pdf-view-midnight-colors '("#d8dee9" . "#2e3440")))) (setopt pdf-view-midnight-colors '("#d8dee9" . "#2e3440"))))
#+end_src #+end_src
One thing ~pdf-tools~ doesnt handle is restoring the PDF to the last One thing ~pdf-tools~ doesnt handle is restoring the PDF to the last
@ -1365,8 +1365,8 @@ doing and what Git is doing! In short, I absolutely love it!
:config :config
(add-hook 'magit-process-find-password-functions 'magit-process-password-auth-source) (add-hook 'magit-process-find-password-functions 'magit-process-password-auth-source)
<<magit-angular-keywords-highlight>> <<magit-angular-keywords-highlight>>
(csetq magit-clone-default-directory "~/fromGIT/" (setopt magit-clone-default-directory "~/fromGIT/"
magit-display-buffer-function #'magit-display-buffer-same-window-except-diff-v1) magit-display-buffer-function #'magit-display-buffer-same-window-except-diff-v1)
(with-eval-after-load 'evil-collection (with-eval-after-load 'evil-collection
(phundrak/evil (phundrak/evil
:packages '(evil-collection magit) :packages '(evil-collection magit)

View File

@ -81,20 +81,20 @@ Since Emacs 29, it is possible to enable drag-and-drop between Emacs
and other applications. and other applications.
#+name: dired-drag-and-drop #+name: dired-drag-and-drop
#+begin_src emacs-lisp :tangle no #+begin_src emacs-lisp :tangle no
(csetq dired-mouse-drag-files t (setopt dired-mouse-drag-files t
mouse-drag-and-drop-region-cross-program t) mouse-drag-and-drop-region-cross-program t)
#+end_src #+end_src
In Dirvish, its best to use the long name of flags whenever possible, In Dirvish, its best to use the long name of flags whenever possible,
otherwise some commands wont work. otherwise some commands wont work.
#+name: dired-listing-flags #+name: dired-listing-flags
#+begin_src emacs-lisp :tangle no #+begin_src emacs-lisp :tangle no
(csetq dired-listing-switches (string-join '("--all" (setopt dired-listing-switches (string-join '("--all"
"--human-readable" "--human-readable"
"--time-style=long-iso" "--time-style=long-iso"
"--group-directories-first" "--group-directories-first"
"-lv1") "-lv1")
" ")) " "))
#+end_src #+end_src
However, it is possible to instead use =eza= when it is available (its However, it is possible to instead use =eza= when it is available (its
@ -121,12 +121,12 @@ files and images.
(my/dir (lambda (path &optional dir) (my/dir (lambda (path &optional dir)
(expand-file-name (file-name-as-directory path) (expand-file-name (file-name-as-directory path)
(or dir user-emacs-directory))))) (or dir user-emacs-directory)))))
(csetq image-dired-thumb-size 150 (setopt image-dired-thumb-size 150
image-dired-dir (funcall my/dir "dired-img") image-dired-dir (funcall my/dir "dired-img")
image-dired-db-file (funcall my/file "dired-db.el") image-dired-db-file (funcall my/file "dired-db.el")
image-dired-gallery-dir (funcall my/dir "gallery") image-dired-gallery-dir (funcall my/dir "gallery")
image-dired-temp-image-file (funcall my/file "temp-image" image-dired-dir) image-dired-temp-image-file (funcall my/file "temp-image" image-dired-dir)
image-dired-temp-rotate-image-file (funcall my/file "temp-rotate-image" image-dired-dir))) image-dired-temp-rotate-image-file (funcall my/file "temp-rotate-image" image-dired-dir)))
#+end_src #+end_src
Copying files with Dired is a blocking process. Its usually fine when Copying files with Dired is a blocking process. Its usually fine when
@ -461,10 +461,10 @@ supported natively. I will describe them here.
:straight (tramp :type built-in :build t) :straight (tramp :type built-in :build t)
:config :config
<<tramp-add-yadm>> <<tramp-add-yadm>>
(csetq tramp-ssh-controlmaster-options nil (setopt tramp-ssh-controlmaster-options nil
tramp-verbose 0 tramp-verbose 0
tramp-auto-save-directory (locate-user-emacs-file "tramp/") tramp-auto-save-directory (locate-user-emacs-file "tramp/")
tramp-chunksize 2000) tramp-chunksize 2000)
(add-to-list 'backup-directory-alist ; deactivate auto-save with TRAMP (add-to-list 'backup-directory-alist ; deactivate auto-save with TRAMP
(cons tramp-file-name-regexp nil))) (cons tramp-file-name-regexp nil)))
#+end_src #+end_src

View File

@ -25,16 +25,16 @@ it bépo-compatible.
:defer t :defer t
:straight t :straight t
:config :config
(csetq avy-keys '(?a ?u ?i ?e ?c ?t ?s ?r ?n) (setopt avy-keys '(?a ?u ?i ?e ?c ?t ?s ?r ?n)
avy-dispatch-alist '((?x . avy-action-kill-move) avy-dispatch-alist '((?x . avy-action-kill-move)
(?X . avy-action-kill-stay) (?X . avy-action-kill-stay)
(?T . avy-action-teleport) (?T . avy-action-teleport)
(?m . avy-action-mark) (?m . avy-action-mark)
(?C . avy-action-copy) (?C . avy-action-copy)
(?y . avy-action-yank) (?y . avy-action-yank)
(?Y . avy-action-yank-line) (?Y . avy-action-yank-line)
(?I . avy-action-ispell) (?I . avy-action-ispell)
(?z . avy-action-zap-to-char))) (?z . avy-action-zap-to-char)))
(defun my/avy-goto-url () (defun my/avy-goto-url ()
"Jump to url with avy." "Jump to url with avy."
(interactive) (interactive)
@ -71,12 +71,12 @@ Whats the point of using Emacs if you cant tell everyone?
:straight (:built t) :straight (:built t)
:defer t :defer t
:config :config
(csetq elcord-use-major-mode-as-main-icon t (setopt elcord-use-major-mode-as-main-icon t
elcord-refresh-rate 5 elcord-refresh-rate 5
elcord-boring-buffers-regexp-list `("^ " elcord-boring-buffers-regexp-list `("^ "
,(rx "*" (+ any) "*") ,(rx "*" (+ any) "*")
,(rx bol (or "Re: " ,(rx bol (or "Re: "
"Fwd: "))))) "Fwd: ")))))
#+end_src #+end_src
** Elpher ** Elpher

View File

@ -60,8 +60,8 @@ it is.
:host github :host github
:repo "Phundrak/appwrite.el") :repo "Phundrak/appwrite.el")
:config :config
(csetq appwrite-endpoint "https://appwrite.phundrak.com" (setopt appwrite-endpoint "https://appwrite.phundrak.com"
appwrite-devel t)) appwrite-devel t))
#+end_src #+end_src
*** Databases *** Databases
@ -1419,11 +1419,11 @@ languages in the same buffer, mainly HTML, CSS, and JavaScript.
("\\.djhtml\\'" . web-mode) ("\\.djhtml\\'" . web-mode)
("\\.vue\\'" . web-mode)) ("\\.vue\\'" . web-mode))
:config :config
(csetq web-mode-markup-indent-offset 2 (setopt web-mode-markup-indent-offset 2
web-mode-code-indent-offset 2 web-mode-code-indent-offset 2
web-mode-css-indent-offset 2 web-mode-css-indent-offset 2
web-mode-style-padding 0 web-mode-style-padding 0
web-mode-script-padding 0) web-mode-script-padding 0)
:general :general
(phundrak/major-leader-key (phundrak/major-leader-key
:keymaps 'web-mode-map :keymaps 'web-mode-map