From 06770985d7539afe97747ae4fff7211e6abea94e Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sat, 4 Sep 2021 10:38:06 -0500 Subject: Sort init.el by package --- lisp/acdw.el | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'lisp') diff --git a/lisp/acdw.el b/lisp/acdw.el index 8db7fea..cf8914f 100644 --- a/lisp/acdw.el +++ b/lisp/acdw.el @@ -19,7 +19,9 @@ ;; functions for me, acdw. ;;; Code: - + +(require 'cl-lib) + ;;; Variables (defconst acdw/system @@ -242,10 +244,12 @@ With a prefix argument N, (un)comment that many sexps." ;;; Sort sexps ;; from https://github.com/alphapapa/unpackaged.el#sort-sexps +;; and https://github.com/alphapapa/unpackaged.el/issues/20 -(defun sort-sexps (beg end) +(defun sort-sexps (beg end &optional key) "Sort sexps in region. -Comments stay with the code below." +Comments stay with the code below. KEY is a function to sort by, +e.g. (lambda (sexp) (symbol-name (car sexp)))" (interactive "r") (cl-flet ((skip-whitespace () (while (looking-at (rx (1+ (or space "\n")))) (goto-char (match-end 0)))) @@ -270,11 +274,16 @@ Comments stay with the code below." for end = (point-marker) while sexp ;; Collect the real string, then one used for sorting. - collect (cons (buffer-substring (marker-position start) (marker-position end)) + collect (cons (buffer-substring (marker-position start) + (marker-position end)) (save-excursion (goto-char (marker-position start)) (skip-both) - (buffer-substring (point) (marker-position end)))) + (if key + (funcall key sexp) + (buffer-substring + (point) + (marker-position end))))) into sexps collect (cons start end) into markers -- cgit 1.4.1-21-gabe81