From d9a7e58f1e6c2db6a004b3b71c5855d8e96c1b9f Mon Sep 17 00:00:00 2001 From: Lucien Cartier-Tilet Date: Sun, 6 Oct 2024 11:58:42 +0200 Subject: [PATCH] docs(emacs): remove csetq, replace it with setopt --- docs/emacs/basic-config.org | 44 --------------------------- docs/emacs/packages/applications.org | 16 +++++----- docs/emacs/packages/emacs-builtin.org | 36 +++++++++++----------- docs/emacs/packages/misc.org | 32 +++++++++---------- docs/emacs/packages/programming.org | 14 ++++----- 5 files changed, 49 insertions(+), 93 deletions(-) diff --git a/docs/emacs/basic-config.org b/docs/emacs/basic-config.org index 4272f5c..4c49369 100644 --- a/docs/emacs/basic-config.org +++ b/docs/emacs/basic-config.org @@ -350,47 +350,3 @@ on the matter. (unless (string= "-" project-name) (format (if (buffer-modified-p) " ◉ %s" "  ●  %s - Emacs") project-name)))))) #+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~ shouldn’t be -the user’s 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 it’s pairs of variables and their value), but -I also had to make the code simply work. diff --git a/docs/emacs/packages/applications.org b/docs/emacs/packages/applications.org index a0d7c1d..5c885da 100644 --- a/docs/emacs/packages/applications.org +++ b/docs/emacs/packages/applications.org @@ -409,13 +409,13 @@ configuration for the ~mu4e~ package itself. <> <> - (csetq mu4e-completing-read-function 'completing-read - mu4e-use-fancy-chars t - message-kill-buffer-on-exit t - mu4e-org-support nil) + (setopt mu4e-completing-read-function 'completing-read + mu4e-use-fancy-chars t + message-kill-buffer-on-exit t + mu4e-org-support nil) (let ((dir (concat (getenv "HOME") "/Downloads/mu4e"))) (when (file-directory-p dir) - (csetq mu4e-attachment-dir dir))) + (setopt mu4e-attachment-dir dir))) (defmacro mu4e-view-mode--prepare () `(lambda () (visual-line-mode 1))) :gfhook ('mu4e-view-mode-hook (mu4e-view-mode--prepare)) @@ -1331,7 +1331,7 @@ dark mode for PDFs. "m" 'pdf-view-midnight-minor-mode) :config (with-eval-after-load 'pdf-view - (csetq pdf-view-midnight-colors '("#d8dee9" . "#2e3440")))) + (setopt pdf-view-midnight-colors '("#d8dee9" . "#2e3440")))) #+end_src One thing ~pdf-tools~ doesn’t 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 (add-hook 'magit-process-find-password-functions 'magit-process-password-auth-source) <> - (csetq magit-clone-default-directory "~/fromGIT/" - magit-display-buffer-function #'magit-display-buffer-same-window-except-diff-v1) + (setopt magit-clone-default-directory "~/fromGIT/" + magit-display-buffer-function #'magit-display-buffer-same-window-except-diff-v1) (with-eval-after-load 'evil-collection (phundrak/evil :packages '(evil-collection magit) diff --git a/docs/emacs/packages/emacs-builtin.org b/docs/emacs/packages/emacs-builtin.org index a4c6822..f029ee5 100644 --- a/docs/emacs/packages/emacs-builtin.org +++ b/docs/emacs/packages/emacs-builtin.org @@ -81,20 +81,20 @@ Since Emacs 29, it is possible to enable drag-and-drop between Emacs and other applications. #+name: dired-drag-and-drop #+begin_src emacs-lisp :tangle no -(csetq dired-mouse-drag-files t - mouse-drag-and-drop-region-cross-program t) +(setopt dired-mouse-drag-files t + mouse-drag-and-drop-region-cross-program t) #+end_src In Dirvish, it’s best to use the long name of flags whenever possible, otherwise some commands won’t work. #+name: dired-listing-flags #+begin_src emacs-lisp :tangle no -(csetq dired-listing-switches (string-join '("--all" - "--human-readable" - "--time-style=long-iso" - "--group-directories-first" - "-lv1") - " ")) +(setopt dired-listing-switches (string-join '("--all" + "--human-readable" + "--time-style=long-iso" + "--group-directories-first" + "-lv1") + " ")) #+end_src However, it is possible to instead use =eza= when it is available (it’s @@ -121,12 +121,12 @@ files and images. (my/dir (lambda (path &optional dir) (expand-file-name (file-name-as-directory path) (or dir user-emacs-directory))))) - (csetq image-dired-thumb-size 150 - image-dired-dir (funcall my/dir "dired-img") - image-dired-db-file (funcall my/file "dired-db.el") - image-dired-gallery-dir (funcall my/dir "gallery") - 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))) + (setopt image-dired-thumb-size 150 + image-dired-dir (funcall my/dir "dired-img") + image-dired-db-file (funcall my/file "dired-db.el") + image-dired-gallery-dir (funcall my/dir "gallery") + 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))) #+end_src Copying files with Dired is a blocking process. It’s usually fine when @@ -461,10 +461,10 @@ supported natively. I will describe them here. :straight (tramp :type built-in :build t) :config <> - (csetq tramp-ssh-controlmaster-options nil - tramp-verbose 0 - tramp-auto-save-directory (locate-user-emacs-file "tramp/") - tramp-chunksize 2000) + (setopt tramp-ssh-controlmaster-options nil + tramp-verbose 0 + tramp-auto-save-directory (locate-user-emacs-file "tramp/") + tramp-chunksize 2000) (add-to-list 'backup-directory-alist ; deactivate auto-save with TRAMP (cons tramp-file-name-regexp nil))) #+end_src diff --git a/docs/emacs/packages/misc.org b/docs/emacs/packages/misc.org index d1fef66..b95c1e3 100644 --- a/docs/emacs/packages/misc.org +++ b/docs/emacs/packages/misc.org @@ -25,16 +25,16 @@ it bépo-compatible. :defer t :straight t :config - (csetq avy-keys '(?a ?u ?i ?e ?c ?t ?s ?r ?n) - avy-dispatch-alist '((?x . avy-action-kill-move) - (?X . avy-action-kill-stay) - (?T . avy-action-teleport) - (?m . avy-action-mark) - (?C . avy-action-copy) - (?y . avy-action-yank) - (?Y . avy-action-yank-line) - (?I . avy-action-ispell) - (?z . avy-action-zap-to-char))) + (setopt avy-keys '(?a ?u ?i ?e ?c ?t ?s ?r ?n) + avy-dispatch-alist '((?x . avy-action-kill-move) + (?X . avy-action-kill-stay) + (?T . avy-action-teleport) + (?m . avy-action-mark) + (?C . avy-action-copy) + (?y . avy-action-yank) + (?Y . avy-action-yank-line) + (?I . avy-action-ispell) + (?z . avy-action-zap-to-char))) (defun my/avy-goto-url () "Jump to url with avy." (interactive) @@ -71,12 +71,12 @@ What’s the point of using Emacs if you can’t tell everyone? :straight (:built t) :defer t :config - (csetq elcord-use-major-mode-as-main-icon t - elcord-refresh-rate 5 - elcord-boring-buffers-regexp-list `("^ " - ,(rx "*" (+ any) "*") - ,(rx bol (or "Re: " - "Fwd: "))))) + (setopt elcord-use-major-mode-as-main-icon t + elcord-refresh-rate 5 + elcord-boring-buffers-regexp-list `("^ " + ,(rx "*" (+ any) "*") + ,(rx bol (or "Re: " + "Fwd: "))))) #+end_src ** Elpher diff --git a/docs/emacs/packages/programming.org b/docs/emacs/packages/programming.org index 0f03f01..ead71b4 100644 --- a/docs/emacs/packages/programming.org +++ b/docs/emacs/packages/programming.org @@ -60,8 +60,8 @@ it is. :host github :repo "Phundrak/appwrite.el") :config - (csetq appwrite-endpoint "https://appwrite.phundrak.com" - appwrite-devel t)) + (setopt appwrite-endpoint "https://appwrite.phundrak.com" + appwrite-devel t)) #+end_src *** Databases @@ -1419,11 +1419,11 @@ languages in the same buffer, mainly HTML, CSS, and JavaScript. ("\\.djhtml\\'" . web-mode) ("\\.vue\\'" . web-mode)) :config - (csetq web-mode-markup-indent-offset 2 - web-mode-code-indent-offset 2 - web-mode-css-indent-offset 2 - web-mode-style-padding 0 - web-mode-script-padding 0) + (setopt web-mode-markup-indent-offset 2 + web-mode-code-indent-offset 2 + web-mode-css-indent-offset 2 + web-mode-style-padding 0 + web-mode-script-padding 0) :general (phundrak/major-leader-key :keymaps 'web-mode-map