From ebf0144bfd93c9b489e9770ef4a8533cec94425f Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Wed, 18 Aug 2021 18:22:23 -0500 Subject: Add `sort-setq' --- lisp/acdw.el | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/lisp/acdw.el b/lisp/acdw.el index 2be0c4e..27f5eff 100644 --- a/lisp/acdw.el +++ b/lisp/acdw.el @@ -513,5 +513,36 @@ It's called 'require-private' for historical reasons." (when (fboundp mode) (funcall mode -1))))) + +;;; Sort setq... +;; https://emacs.stackexchange.com/questions/33039/ + +(defun sort-setq () + (interactive) + (save-excursion + (save-restriction + (let ((sort-end (progn (end-of-defun) + (backward-char) + (point-marker))) + (sort-beg (progn (beginning-of-defun) + (re-search-forward "[ \\t]*(" (point-at-eol)) + (forward-sexp) + (re-search-forward "\\<" (point-at-eol)) + (point-marker)))) + (narrow-to-region (1- sort-beg) (1+ sort-end)) + (sort-subr nil #'sort-setq-next-record #'sort-setq-end-record))))) + +(defun sort-setq-next-record () + (condition-case nil + (progn + (forward-sexp 1) + (backward-sexp)) + ('scan-error (end-of-buffer)))) + +(defun sort-setq-end-record () + (condition-case nil + (forward-sexp 2) + ('scan-error (end-of-buffer)))) + (provide 'acdw) ;;; acdw.el ends here -- cgit 1.4.1-21-gabe81