summary refs log tree commit diff stats
path: root/lisp
diff options
context:
space:
mode:
authorCase Duckworth2021-09-16 08:41:56 -0500
committerCase Duckworth2021-09-16 08:41:56 -0500
commitea9749918dc13799b2ddef42c86c95ce2d0cb4ad (patch)
treed0de90be2c8fbbdf431ca9275ecc37c0a4d26b95 /lisp
parentIndentation (diff)
parentRemove gforth setup (diff)
downloademacs-ea9749918dc13799b2ddef42c86c95ce2d0cb4ad.tar.gz
emacs-ea9749918dc13799b2ddef42c86c95ce2d0cb4ad.zip
Merge branch 'main' of tildegit.org:acdw/emacs
Diffstat (limited to 'lisp')
-rw-r--r--lisp/acdw.el34
1 files changed, 27 insertions, 7 deletions
diff --git a/lisp/acdw.el b/lisp/acdw.el index 40aff5d..dcf7b19 100644 --- a/lisp/acdw.el +++ b/lisp/acdw.el
@@ -265,10 +265,16 @@ With a prefix argument N, (un)comment that many sexps."
265;; from https://github.com/alphapapa/unpackaged.el#sort-sexps 265;; from https://github.com/alphapapa/unpackaged.el#sort-sexps
266;; and https://github.com/alphapapa/unpackaged.el/issues/20 266;; and https://github.com/alphapapa/unpackaged.el/issues/20
267 267
268(defun sort-sexps (beg end &optional key) 268(defun sort-sexps (beg end &optional key-fn sort-fn)
269 "Sort sexps between BEG and END. 269 "Sort sexps between BEG and END.
270Comments stay with the code below. KEY is a function to sort by, 270Comments stay with the code below.
271e.g. (lambda (sexp) (symbol-name (car sexp)))" 271
272Optional argument KEY-FN will determine where in each sexp to
273start sorting. e.g. (lambda (sexp) (symbol-name (car sexp)))
274
275Optional argument SORT-FN will determine how to sort two sexps'
276strings. It's passed to `sort'. By default, it sorts the sexps
277with `string<' starting with the key determined by KEY-FN."
272 (interactive "r") 278 (interactive "r")
273 (cl-flet ((skip-whitespace () (while (looking-at (rx (1+ (or space "\n")))) 279 (cl-flet ((skip-whitespace () (while (looking-at (rx (1+ (or space "\n"))))
274 (goto-char (match-end 0)))) 280 (goto-char (match-end 0))))
@@ -298,8 +304,8 @@ e.g. (lambda (sexp) (symbol-name (car sexp)))"
298 (save-excursion 304 (save-excursion
299 (goto-char (marker-position start)) 305 (goto-char (marker-position start))
300 (skip-both) 306 (skip-both)
301 (if key 307 (if key-fn
302 (funcall key sexp) 308 (funcall key-fn sexp)
303 (buffer-substring 309 (buffer-substring
304 (point) 310 (point)
305 (marker-position end))))) 311 (marker-position end)))))
@@ -307,8 +313,9 @@ e.g. (lambda (sexp) (symbol-name (car sexp)))"
307 collect (cons start end) 313 collect (cons start end)
308 into markers 314 into markers
309 finally return (list sexps markers)) 315 finally return (list sexps markers))
310 (setq sexps (sort sexps (lambda (a b) 316 (setq sexps (sort sexps (if sort-fn sort-fn
311 (string< (cdr a) (cdr b))))) 317 (lambda (a b)
318 (string< (cdr a) (cdr b))))))
312 (cl-loop for (real . sort) in sexps 319 (cl-loop for (real . sort) in sexps
313 for (start . end) in markers 320 for (start . end) in markers
314 do (progn 321 do (progn
@@ -688,5 +695,18 @@ When called with PREFIX, just kill Emacs without confirmation."
688 (ignore-errors 695 (ignore-errors
689 (delete-frame)))) 696 (delete-frame))))
690 697
698
699;;; cribbed
700
701;; https://jao.io/blog/2021-09-08-high-signal-to-noise-emacs-command.html
702(defun jao-buffer-same-mode (&rest modes)
703 "Pop to a buffer with a mode among MODES, or the current one if not given."
704 (interactive)
705 (let* ((modes (or modes (list major-mode)))
706 (pred (lambda (b)
707 (let ((b (get-buffer (if (consp b) (car b) b))))
708 (member (buffer-local-value 'major-mode b) modes)))))
709 (pop-to-buffer (read-buffer "Buffer: " nil t pred))))
710
691(provide 'acdw) 711(provide 'acdw)
692;;; acdw.el ends here 712;;; acdw.el ends here