Dirvish, easy-escape, and devdocs

This commit is contained in:
2024-12-24 03:50:06 -08:00
parent 96b64a144e
commit b307a21e11
2 changed files with 285 additions and 1 deletions

View File

@ -179,3 +179,170 @@
;; (add-to-list 'aggressive-indent-protected-commands
;; #'evil-undo))
;; ;; easier identification of local variables
;; (use-package color-identifiers-mode
;; :hook (prog-mode . color-identifiers-mode-maybe)
;; :init
;; (setq color-identifiers:num-colors 10
;; color-identifiers:recoloring-delay 0.5)
;; :config
;; ;; make sure that remapped treesitter modes are handled
;; (defun my/color-identifiers-mode-remap-ts-modes ()
;; (dolist (entry color-identifiers:modes-alist)
;; (cl-destructuring-bind (mode &rest props) entry
;; (when-let ((remapped-mode (alist-get mode major-mode-remap-alist))
;; ((string-match-p "-ts-" (symbol-name remapped-mode)))
;; ((not (assq remapped-mode color-identifiers:modes-alist))))
;; ;; no need to test with `add-to-list'
;; (push (cons remapped-mode props) color-identifiers:modes-alist)))))
;; (my/color-identifiers-mode-remap-ts-modes)
;; (setf (alist-get 'lisp-interaction-mode color-identifiers:modes-alist)
;; (alist-get 'emacs-lisp-mode color-identifiers:modes-alist))
;; (defun my/-color-identifiers-elisp-handle-let-like (sexp output)
;; (cl-destructuring-bind (_name &optional vars &rest body) sexp
;; (dolist (entry vars body)
;; (cond
;; ((and entry (symbolp entry)) (puthash entry t output))
;; ((and (car entry) (symbolp (car entry)))
;; (puthash (car entry) t output))))))
;; (defun my/-color-identifiers-parse-lambda-list (list output)
;; (dolist (entry list)
;; (cond
;; ((and entry (symbolp entry)
;; (not (string-prefix-p ":" (symbol-name entry)))
;; (not (string-prefix-p "&" (symbol-name entry))))
;; (puthash entry t output))
;; ((and (car-safe entry) (symbolp (car entry)))
;; (puthash (car entry) t output)))))
;; (defun my/-color-identifiers-elisp-handle-destructing-bind-like
;; (sexp output)
;; (cl-destructuring-bind (_name &optional vars &rest expr-and-body) sexp
;; (my/-color-identifiers-parse-lambda-list vars output)
;; expr-and-body))
;; (defun my/-color-identifiers-elisp-handle-defun-like
;; (sexp output)
;; (cl-destructuring-bind (_name _func &optional vars &rest body) sexp
;; (my/-color-identifiers-parse-lambda-list vars output)
;; body))
;; (defun my/-color-identifiers-elisp-handle-dolist-like
;; (sexp output)
;; (cl-destructuring-bind (_name &optional spec &rest body) sexp
;; (cl-destructuring-bind (&optional var &rest forms) spec
;; (when (symbolp var)
;; (puthash var t output))
;; (append body forms))))
;; (defun my/-color-identifiers-elisp-handle-loop (sexp output)
;; (let (body-forms)
;; (cl-maplist
;; (lambda (kwds)
;; (cl-case (car kwds)
;; (for ;; this could be a dotted list
;; (let ((tail (ensure-list (cadr kwds))))
;; (while tail
;; (when (and (consp tail) (symbolp (car tail)))
;; (puthash (car tail) t output))
;; (when (and (consp tail) (symbolp (cdr tail)))
;; (puthash (cdr tail) t output))
;; (setq tail (cdr-safe tail)))))
;; (using
;; (when (and (listp (cdr kwds))
;; (symbolp (cl-second (cdr kwds))))
;; (puthash (cl-second (cdr kwds)) t output)))
;; ((with into)
;; (when (symbolp (cadr kwds))
;; (puthash (cadr kwds) t output)))
;; (t
;; (unless (atom (car kwds))
;; (push (car kwds) body-forms)))))
;; (cdr sexp))
;; body-forms))
;; (defun my/-color-identifiers-elisp-handle-do-like (sexp output)
;; (let ((eval-forms))
;; (cl-destructuring-bind (name &optional vars test-forms &rest body) sexp
;; (dolist (entry vars (append eval-forms test-forms body))
;; (cl-destructuring-bind (&optional var init step &rest _)
;; entry
;; (when (symbolp var)
;; (puthash var t output)
;; (cl-callf nconc eval-forms (list init step))))))))
;; (defvar my/-color-identifiers-eslip-handlers
;; (let ((table (make-hash-table)))
;; (puthash 'quote #'ignore table)
;; (puthash 'function #'ignore table)
;; (puthash 'let #'my/-color-identifiers-elisp-handle-let-like table)
;; (puthash 'let* #'my/-color-identifiers-elisp-handle-let-like table)
;; (puthash 'cl-destructuring-bind
;; #'my/-color-identifiers-elisp-handle-destructing-bind-like table)
;; (puthash 'with-slots
;; #'my/-color-identifiers-elisp-handle-destructing-bind-like table)
;; (puthash 'lambda
;; #'my/-color-identifiers-elisp-handle-destructing-bind-like table)
;; (puthash 'cl-function
;; #'my/-color-identifiers-elisp-handle-destructing-bind-like table)
;; (puthash 'defun
;; #'my/-color-identifiers-elisp-handle-defun-like table)
;; (puthash 'cl-defun
;; #'my/-color-identifiers-elisp-handle-defun-like table)
;; (puthash 'defmacro
;; #'my/-color-identifiers-elisp-handle-defun-like table)
;; (puthash 'cl-defmacro
;; #'my/-color-identifiers-elisp-handle-defun-like table)
;; (puthash 'cl-defmacro
;; #'my/-color-identifiers-elisp-handle-defun-like table)
;; (puthash 'cl-loop
;; #'my/-color-identifiers-elisp-handle-loop table)
;; (puthash 'dolist
;; #'my/-color-identifiers-elisp-handle-dolist-like table)
;; (puthash 'dotimes
;; #'my/-color-identifiers-elisp-handle-dolist-like table)
;; (puthash 'cl-dolist
;; #'my/-color-identifiers-elisp-handle-dolist-like table)
;; (puthash 'cl-dotimes
;; #'my/-color-identifiers-elisp-handle-dolist-like table)
;; (puthash 'cl-do
;; #'my/-color-identifiers-elisp-handle-do-like table)
;; table)
;; "A list of functions that find declarations in variables.
;; This is used in `my/-color-identifiers-elisp-declarations-in-sexp'. It is a
;; hash table of function (or macro) names and a function that handles them. The
;; functions should be of two arguments. The first is the sexp to parse. The
;; second is a hash table with the keys being the symbols of local variables. The
;; function should return a list of the forms that it contains that should be
;; recursively searched.")
;; (defun my/-color-identifiers-lisp-declarations-in-sexp (sexp output table)
;; "Get all of the variable declarations in SEXP and place them in OUTPUT.
;; OUTPUT is a hash table. TABLE is a table like
;; `my/-color-identifiers-elisp-declarations-in-sexp'."
;; (let ((stack (list sexp)))
;; (while (and stack (not (input-pending-p)))
;; (let ((entry (pop stack)))
;; (when (proper-list-p entry)
;; (if-let ((handler (gethash (car entry) table)))
;; (cl-callf nconc stack
;; (copy-sequence (funcall handler entry output)))
;; (cl-callf nconc stack
;; (copy-sequence (cdr entry)))))))))
;; (defun my/-color-identifiers-lisp-declarations-in-buffer (&optional buffer)
;; (let ((result (make-hash-table)))
;; (save-excursion
;; (goto-char (point-min))
;; (condition-case nil
;; (while t
;; (condition-case nil
;; (let ((sexp (read (or buffer (current-buffer)))))
;; (my/-color-identifiers-lisp-declarations-in-sexp
;; sexp result my/-color-identifiers-eslip-handlers))
;; (invalid-read-syntax nil)))
;; (end-of-file nil))
;; (let ((names))
;; (maphash (lambda (k _v)
;; (unless (or (eq k t) (not k) (boundp k))
;; (push (symbol-name k) names)))
;; result)
;; names))))
;; (color-identifiers:set-declaration-scan-fn
;; 'emacs-lisp-mode
;; 'my/-color-identifiers-lisp-declarations-in-buffer)
;; (color-identifiers:set-declaration-scan-fn
;; 'lisp-interaction-mode
;; 'my/-color-identifiers-lisp-declarations-in-buffer))