Reduce the number of flymake errors in init.el

This commit is contained in:
Gerard Vermeulen 2024-04-18 17:03:25 +02:00
parent be280ee7ee
commit 9d7269a5c6

View File

@ -322,6 +322,8 @@ of [[info:emacs#Saving Customizations][saving customizations (info)]].
;; Enable `package-install-upgrade-built-in' to upgrade Org and transient.
;; Caveat: works with `list-packages' but not with `package-upgrade-all'.
;; Disable upgrading other packages by pinning them to "nongnu".
(defvar package-pinned-packages)
(setopt package-install-upgrade-built-in t
package-pinned-packages
(cl-union '((bind-key . "nongnu")
@ -392,6 +394,8 @@ version.
#+caption: Install the selected packages.
#+name: lst:install-selected-packages
#+begin_src emacs-lisp -n :results silent
(defvar package-selected-packages)
(unless noninteractive
(unless (require 'no-littering nil 'noerror)
(unless (bound-and-true-p package-archive-contents)
@ -679,8 +683,8 @@ and [[lst:3rd-window-management]] implement a selection of his recommendations.
(defun make-display-buffer-matcher-function (major-modes)
"Return a lambda function to match a list of MAJOR-MODES."
(lambda (buffer-name action)
(with-current-buffer buffer-name (apply #'derived-mode-p major-modes))))
(lambda (buf-name _action)
(with-current-buffer buf-name (apply #'derived-mode-p major-modes))))
(keymap-global-set "M-o" #'other-window))
#+end_src
@ -1434,12 +1438,16 @@ histories.
(setopt savehist-additional-variables '(kill-ring search-ring))
(savehist-mode +1))
(when (and (ensure-package-installation 'vertico)
(fboundp 'vertico-mode))
(vertico-mode +1))
(fboundp 'vertico-directory-delete-char)
(fboundp 'vertico-directory-delete-word)
(fboundp 'vertico-mode)
(fboundp 'vertico-directory-enter))
(vertico-mode +1)
(with-eval-after-load 'vertico
(keymap-set vertico-map "RET" #'vertico-directory-enter)
(defvar vertico-map)
(keymap-set vertico-map "DEL" #'vertico-directory-delete-char)
(keymap-set vertico-map "M-DEL" #'vertico-directory-delete-word))
(keymap-set vertico-map "M-DEL" #'vertico-directory-delete-word)
(keymap-set vertico-map "RET" #'vertico-directory-enter)))
#+end_src
#+attr_latex: :booktabs yes :float table
@ -1649,13 +1657,17 @@ Consult usage tips are:
#+caption: Implement =find-file= with previewing before selection.
#+name: lst:find-file-preview
#+begin_src emacs-lisp -n :results silent
(defun consult-find-file-preview(cue &optional dir default mustmatch init pred)
(defun consult-find-file-preview
(prompt &optional dir _default mustmatch initial predicate)
"Helper to implement previewing when calling `find-file'.
See `read-file-name' for the meaning of PROMPT, DIR, MUSTMATCH, INITIAL,
and PREDICATE."
(interactive)
(let ((default-directory (or dir default-directory))
(minibuffer-completing-file-name t))
(consult--read #'read-file-name-internal :state (consult--file-preview)
:prompt cue :initial init
:require-match mustmatch :predicate pred)))
:prompt prompt :initial initial
:require-match mustmatch :predicate predicate)))
(defun toggle-find-file-preview ()
"Toggle previewing when calling `find-file'."
@ -1680,7 +1692,8 @@ configures =company= after ensuring the =company= installation.
#+caption: Setup =company=.
#+name: lst:setup-company
#+begin_src emacs-lisp -n :results silent
(when (ensure-package-installation 'company)
(when (and (ensure-package-installation 'company)
(fboundp 'company-mode))
;; https://github.com/purcell/emacs.d/issues/778
(setopt company-transformers '(company-sort-by-occurrence))
(dolist (symbol '(LaTeX-mode-hook
@ -1864,7 +1877,7 @@ regexp strings.
#+caption: Ensure =xr= installation.
#+name: lst:ensure-xr-installation
#+begin_src emacs-lisp -n :results silent
(when (ensure-package-installation 'xr))
(when (ensure-package-installation 'xr) t)
#+end_src
* [[info:emacs#Version Control][Version Control (info)]]
@ -1887,17 +1900,17 @@ single frame and to make all text visible prior to ediffing Org buffers.
#+caption: Setup =ediff=.
#+name: lst:setup-ediff
#+begin_src emacs-lisp -n :results silent
(with-eval-after-load 'emacs
(with-eval-after-load 'ediff-wind
(when (fboundp 'ediff-setup-windows-plain)
(setopt ediff-merge-split-window-function #'split-window-horizontally
ediff-split-window-function #'split-window-horizontally
ediff-window-setup-function #'ediff-setup-windows-plain))
ediff-window-setup-function #'ediff-setup-windows-plain)))
(with-eval-after-load 'org
;; https://github.com/oantolin/emacs-config#readme
(add-hook 'org-mode-hook
(defun ediff-with-org-show-all ()
"Expand all headings prior to ediffing org buffers."
(add-hook 'ediff-prepare-buffer-hook #'org-fold-show-all nil t))
(add-hook 'org-mode-hook #'ediff-with-org-show-all))
(add-hook 'ediff-prepare-buffer-hook #'org-fold-show-all nil t))))
#+end_src
** [[https://git-scm.com/book/en/v2][Git]]
@ -2105,7 +2118,6 @@ configuration objectives:
TeX-engine 'luatex
TeX-indent-close-delimiters "]"
TeX-indent-open-delimiters "["
TeX-install-font-lock #'font-latex-setup
TeX-parse-self t
;; Disable `TeX-electric-math' to prevent collisions with `smartparens'.
TeX-electric-math nil)))
@ -2165,7 +2177,7 @@ configuration objectives:
#+caption: Configure =markdown-mode=.
#+name: lst:configure-markdown-mode
#+begin_src emacs-lisp -n :results silent
(when (ensure-package-installation 'markdown-mode))
(when (ensure-package-installation 'markdown-mode) t)
#+end_src
** Writing [[info:org#Top][Org (info)]] files and [[info:org#Activation][Org activation (info)]]
@ -2333,7 +2345,8 @@ Watch out for completion `visit-tags-table' prompts."
(with-eval-after-load 'ob-lisp
;; Default to `sly-eval' whenever feasible:
(when (package-installed-p 'sly)
(when (and (package-installed-p 'sly)
(fboundp 'sly-eval))
(setopt org-babel-lisp-eval-fn #'sly-eval)))
#+end_src
@ -2341,10 +2354,10 @@ Watch out for completion `visit-tags-table' prompts."
#+caption: Unevaluable source blocks.
#+name: lst:no-org-babel-eval
#+begin_src emacs-lisp -n :results silent
(setq org-babel-default-header-args:conf '((:eval . "no")))
(setq org-babel-default-header-args:diff '((:eval . "no")))
(setq org-babel-default-header-args:text '((:eval . "no")))
(setq org-babel-default-header-args:toml '((:eval . "no")))
(defvar org-babel-default-header-args:conf '((:eval . "no")))
(defvar org-babel-default-header-args:diff '((:eval . "no")))
(defvar org-babel-default-header-args:text '((:eval . "no")))
(defvar org-babel-default-header-args:toml '((:eval . "no")))
;;; Kludges to silence `org-lint' warnings:
(defun org-babel-execute:conf (_body _params)
@ -2390,7 +2403,6 @@ Undo this by means of `org-delete-property-globally'."
#+caption: Setup =org-mode-map= 1.
#+name: lst:setup-org-mode-map-1
#+begin_src emacs-lisp -n :results silent
(with-eval-after-load 'emacs
;; From: "Nicolas Richard" <theonewiththeevillook@yahoo.fr>
;; Date: Fri, 08 Mar 2013 16:23:02 +0100 [thread overview]
;; Message-ID: <87vc913oh5.fsf@yahoo.fr> (raw)
@ -2428,14 +2440,13 @@ When called twice, replace the previously inserted \\(\\) by one $."
(keymap-set org-mode-map "C-c <SPC>" #'org-inactive-current-time-stamp)
(keymap-set org-mode-map "C-c C-<SPC>" #'org-active-current-time-stamp)
(keymap-set org-mode-map "$" #'org-electric-dollar)
(keymap-set org-mode-map "M-q" #'org-fill-paragraph)))
(keymap-set org-mode-map "M-q" #'org-fill-paragraph))
#+end_src
#+caption[Setup =org-mode-map= 2]:
#+caption: Setup =org-mode-map= 2.
#+name: lst:setup-org-mode-map-2
#+begin_src emacs-lisp -n :results silent
(with-eval-after-load 'emacs
;; Stolen from `org-insert-structure-template'.
;; Note: `org-tempo' does not require `tempo' at all.
(defcustom org-insert-source-block-defaults
@ -2447,7 +2458,8 @@ When called twice, replace the previously inserted \\(\\) by one $."
"org -n"
"python -i -n :results silent")
"Default values for `org-insert-source-block'."
:group 'org)
:group 'org
:type '(repeat string))
(defun org-insert-source-block ()
"Insert a source block #+begin_src/SPEC/BODY/#+end_src.
@ -2477,7 +2489,7 @@ region becomes the block BODY. Otherwise, insert an empty block."
(insert "#+end_src")
(if (looking-at "[ \t]*$") (replace-match "") (insert "\n"))
(when (and (eobp) (not (bolp))) (insert "\n")))
(end-of-line)))))
(end-of-line))))
(with-eval-after-load 'org
(keymap-set org-mode-map "C-c C-;" #'org-insert-source-block))
@ -3433,17 +3445,11 @@ The listings below implement or reimplement three groups of =org-link= types:
#+caption: Define an =org-link= type for =pdf-tools=.
#+name: lst:define-org-pdfview-link-type
#+begin_src emacs-lisp -n :results silent
(with-eval-after-load 'ol
(autoload 'pdf-view-goto-page
"Go to PAGE in PDF with optional WINDOW to go to PAGE in all windows."
nil t)
(org-link-set-parameters "pdfview"
:follow #'org-pdfview-open
:export #'org-pdfview-export
:store #'org-pdfview-store-link)
(declare-function pdf-view-current-page "pdf-macs" (&optional window))
(declare-function pdf-view-goto-page "pdf-view" (page &optional window))
(defun org-pdfview-export (link description backend _)
"Export a \"pdfview\" type link.
"Export LINK as a \"pdfview\" type link using DESCRIPTION and export BACKEND.
The paths of the links export as file relative paths in order to
facilate moving single directories or whole directory trees."
(let ((path (if (string-match "\\(.+\\)::.+" link)
@ -3459,7 +3465,7 @@ facilate moving single directories or whole directory trees."
(_ path)))))
(defun org-pdfview-open (link _)
"Open a \"pdfview\" type link."
"Open LINK as a \"pdfview\" type link."
(string-match "\\(.*?\\)\\(?:::\\([0-9]+\\)\\)?$" link)
(let ((path (match-string 1 link))
(page (and (match-beginning 2)
@ -3477,13 +3483,22 @@ facilate moving single directories or whole directory trees."
(org-link-store-props
:type "pdfview"
:link link
:description path)))))
:description path))))
(with-eval-after-load 'ol
(org-link-set-parameters "pdfview"
:follow #'org-pdfview-open
:export #'org-pdfview-export
:store #'org-pdfview-store-link))
#+end_src
#+caption[Patch =ol-info=]:
#+caption: Patch =ol-info=.
#+name: lst:patch-org-info-link-type
#+begin_src emacs-lisp -n :exports code :results silent
(declare-function org-info-map-html-url "ol-info" (filename))
(declare-function org-info--expand-node-name "ol-info" (node))
(with-eval-after-load 'ol-info
(defun org-info-export (path desc format)
"Export an info link.
@ -3553,6 +3568,11 @@ The following posts provide programming information:
#+name: lst:define-org-yt-link-type
#+begin_src emacs-lisp -n :results silent
;; https://bitspook.in/blog/extending-org-mode-to-handle-youtube-paths/
(declare-function emms-add-url "emms-source-file" (url))
(declare-function emms-playlist-last "emms" ())
(declare-function emms-playlist-mode-play-current-track "emms-playlist-mode" ())
(declare-function with-current-emms-playlist "emms" (&rest body))
(defun org-yt-emms-open (path)
"Open an \"YouTube\" PATH link with `emms' using \"mpv\"."
(let ((url (format "https://www.youtube.com/watch?v=%s" path)))
@ -4425,16 +4445,11 @@ it for this buffer is by typing {{{kbd(C-c C-e t U)}}} to export the it to a
(when (and (ensure-package-installation 'writegood-mode)
(fboundp 'writegood-mode))
(defcustom writegood-mode-for '(org-mode text-mode)
"List of modes for which to enable `writegood-mode'."
:group 'writegood
:type '(repeat symbol))
(add-hook 'after-init-hook
(defun on-after-change-mode-hook-enable-writegood-mode ()
(add-hook 'after-change-major-mode-hook
(defun enable-writegood-mode ()
(when (derived-mode-p writegood-mode-for)
(when (derived-mode-p '(org-mode text-mode))
(writegood-mode +1)))))
'depth)
@ -4462,8 +4477,8 @@ true in case document headlines contain links. The code in listing
(setopt which-func-modes
'(emacs-lisp-mode org-mode pdf-view-mode)))
;; It looks like `python-mode' does nothing when they it is an element
;; of `which-func-modes'.
;; It looks like `python-mode' does nothing when it is an element of
;; `which-func-modes'.
;; (setopt which-func-modes t)
@ -4475,6 +4490,8 @@ true in case document headlines contain links. The code in listing
#+name: lst:define-for-which-func-functions
#+begin_src emacs-lisp -n :results silent
;; https://emacs.stackexchange.com/questions/30894/
(declare-function pdf-info-outline "pdf-info" (&optional file-or-buffer))
(declare-function org-element-type-p "org-element-ast" (node types))
(defvar which-func-functions nil)
(defun which-func-org-function ()
@ -4496,7 +4513,6 @@ Return the document title when point is above the first headline."
(count (length chain)))
(setq text (format "%s|%s" count (nth (1- count) chain)))))
text)))
(add-to-list 'which-func-functions 'which-func-org-function)
(defun which-func-pdf-view-function ()
@ -4519,7 +4535,6 @@ Return \"Front Matter\" when current page is above the first headline."
(setq new-title (alist-get 'title (nth hl-index outline)))
(cl-incf hl-index))
(if (< current-page hl-page) old-title new-title))))
(add-to-list 'which-func-functions 'which-func-pdf-view-function)
#+end_src
@ -4617,6 +4632,7 @@ julia --project=eglot-jl-20240318.1159/ eglot-jl-20240318.1159/eglot-jl.jl
#+name: lst:eglot-maybe-ensure
#+begin_src emacs-lisp -n :results silent
(defun eglot-maybe-ensure ()
"Call `eglot-ensure' under favorable conditions."
(when (and (apply #'derived-mode-p '(python-mode))
(assoc 'eglot-workspace-configuration dir-local-variables-alist))
(eglot-ensure)))
@ -6501,7 +6517,7 @@ setup and requires no configuration.
#+name: lst:configure-ws-butler
#+begin_src emacs-lisp -n :results silent
(when (and (ensure-package-installation 'ws-butler)
(require 'ws-butler nil 'noerror))
(fboundp 'ws-butler-mode))
(setopt ws-butler-keep-whitespace-before-point nil)
(add-hook 'prog-mode-hook #'ws-butler-mode)
(add-hook 'text-mode-hook #'ws-butler-mode))
@ -6568,9 +6584,11 @@ contrary to for instance [[https://github.com/Fanael/rainbow-delimiters#readme][
("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 symbol #'smartparens-mode)))
(when (fboundp 'smartparens-strict-mode)
(dolist (symbol '(emacs-lisp-mode-hook
go-ts-mode-hook
ielm-mode-hook
@ -6579,7 +6597,7 @@ contrary to for instance [[https://github.com/Fanael/rainbow-delimiters#readme][
lisp-mode-hook
python-mode-hook
sly-mrepl-mode-hook))
(add-hook symbol #'smartparens-strict-mode))
(add-hook symbol #'smartparens-strict-mode)))
(when (fboundp 'go-ts-mode)
;; Stolen from `smartparens-go':
@ -6672,11 +6690,12 @@ formatter for Python]].
(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 symbol #'yas-minor-mode))))
#+end_src
* [[info:emacs#Display][Display (info)]]
@ -6719,8 +6738,8 @@ applies first. Narrowing to org-src-block actually calls
With prefix P, don't widen, just narrow even if buffer is already
narrowed."
(declare (interactive-only t))
(interactive "P")
(declare (interactive-only))
(cond ((and (buffer-narrowed-p) (not p))
(widen))
((and (bound-and-true-p org-src-mode) (not p))