From 702502bbdd83619abd1f11c2ff76eea1bd1d9cb2 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Fri, 28 Jan 2022 17:25:16 -0600 Subject: Allow +open-paragraph to open a paragraph above --- lisp/acdw.el | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'lisp') diff --git a/lisp/acdw.el b/lisp/acdw.el index d805a10..c2f9767 100644 --- a/lisp/acdw.el +++ b/lisp/acdw.el @@ -131,19 +131,24 @@ active, or else the entire buffer." (= (line-beginning-position) (line-end-position))) (insert "\n"))))) -(defun +open-paragraph () +(defun +open-paragraph (&optional arg) "Open a paragraph after paragraph at point. A paragraph is defined as continguous non-empty lines of text surrounded by empty lines, so opening a paragraph means to make -three blank lines, then place the point on the second one." - (interactive "*") +three blank lines, then place the point on the second one. + +Called with prefix ARG, open a paragraph before point." + ;; TODO: Take an integer as ARG, allowing for skipping paragraphs up and down. + (interactive "*P") + ;; TODO: add `+open-paragraph-ignore-modes' (unless (derived-mode-p 'special-mode 'lui-mode 'comint-mode) ;; Go to next blank line. This /isn't/ `end-of-paragraph-text' because ;; that's weird with org, and I'm guessing other modes too. + (unless (looking-at "^$") (forward-line (if arg -1 +1))) (while (and (not (looking-at "^$")) - (< (point) (point-max))) - (forward-line 1)) + (= 0 (forward-line (if arg -1 +1))))) (newline) + (when arg (newline) (forward-line -2)) (delete-blank-lines) (newline 2) (previous-line))) @@ -241,5 +246,18 @@ UNIT can be one of :kb, :mb, :gb, :tb, :pb, :eb, :zb, :yb; :kib, :mib, :gib, nil `((,keyword-regexp 1 'font-lock-todo-face prepend))))) +;; I don't use this much but I always forget the exact implementation, so this +;; is more to remember than anything else. +(defmacro setc (&rest vars-and-vals) + "Set VARS-AND-VALS by customizing them or using set-default. +Use like `setq'." + `(progn ,@(cl-loop for (var val) on vars-and-vals by #'cddr + if (null val) return (user-error "Not enough arguments") + collecting `(funcall (or (get ',var 'custom-get) + #'set-default) + ',var ',val) + into ret + finally return ret))) + (provide 'acdw) ;;; acdw.el ends here -- cgit 1.4.1-21-gabe81