From 8d8e56272eded6abff514ab08a8b515e63672561 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sat, 14 Aug 2021 12:39:31 -0500 Subject: Use `unfill' package and delete `kill-ring-save-unfilled' `acdw/copy-region-plain' takes care of what I want it to. --- lisp/acdw.el | 15 --------------- 1 file changed, 15 deletions(-) (limited to 'lisp') diff --git a/lisp/acdw.el b/lisp/acdw.el index eab0719..4c17bcb 100644 --- a/lisp/acdw.el +++ b/lisp/acdw.el @@ -87,21 +87,6 @@ ARG). When called with multiple arguments or a list, it returns (save-restriction (unfill-region (point-min) (point-max)))))) -(defun kill-ring-save-unfilled (start end &optional region) - "Unfill, kill, then re-fill the region defined by START and END positions. -REGION is passed straight to `kill-ring-save'." - (interactive "*r") - (let ((sentence-end-double-space nil)) - (unfill-region start end) - (kill-ring-save - ;; A quick hack to try and ameliorate the "Args out of range" error when - ;; `unfill-region' removes some newlines. I'm not sure if this will work - ;; if calling from Lisp or other such nonsense. - (max start (point-min)) - (min end (point-max)) - region)) - (fill-region start end)) - (defmacro when-unfocused (name &rest forms) "Define a function NAME, executing FORMS, that fires when Emacs is unfocused." -- cgit 1.4.1-21-gabe81 From 4b3ebd99a0f0a3ea95e2d60c63d8d6f9273922e0 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sat, 14 Aug 2021 12:40:52 -0500 Subject: Implement `with-eval-after-loads' macro --- init.el | 26 ++++++++++++-------------- lisp/acdw.el | 16 ++++++++++++++++ 2 files changed, 28 insertions(+), 14 deletions(-) (limited to 'lisp') diff --git a/init.el b/init.el index 703dc56..4209a6b 100644 --- a/init.el +++ b/init.el @@ -1009,15 +1009,14 @@ if ripgrep is installed, otherwise `consult-grep'." (:advise completing-read-multiple :filter-args #'crm-indicator)) - (with-eval-after-load 'vertico - (with-eval-after-load 'consult - (when (boundp 'consult-crm-map) - (define-key consult-crm-map "\r" #'+vertico-crm-exit) - (define-key consult-crm-map "\t" #'vertico-exit) - (defun +vertico-crm-exit () - (interactive) - (run-at-time 0 nil #'vertico-exit) - (funcall #'vertico-exit)))))) + (with-eval-after-loads (vertico consult) + (when (boundp 'consult-crm-map) + (define-key consult-crm-map "\r" #'+vertico-crm-exit) + (define-key consult-crm-map "\t" #'vertico-exit) + (defun +vertico-crm-exit () + (interactive) + (run-at-time 0 nil #'vertico-exit) + (funcall #'vertico-exit))))) (setup (:straight crux) @@ -1089,11 +1088,10 @@ if ripgrep is installed, otherwise `consult-grep'." #'which-key--hide-popup-ignore-command) embark-become-indicator embark-action-indicator) - (with-eval-after-load 'embark - (with-eval-after-load 'consult - (setup (:straight embark-consult) - (add-hook 'embark-collect-mode-hook - #'consult-preview-at-point-mode))))) + (with-eval-after-loads (embark consult) + (setup (:straight embark-consult) + (add-hook 'embark-collect-mode-hook + #'consult-preview-at-point-mode)))) (setup (:straight epithet) (add-hook 'Info-selection-hook #'epithet-rename-buffer) diff --git a/lisp/acdw.el b/lisp/acdw.el index 4c17bcb..2aa6c1f 100644 --- a/lisp/acdw.el +++ b/lisp/acdw.el @@ -108,6 +108,22 @@ is unfocused." ,@body) (message "%s... Done." ,message))) +(defmacro with-eval-after-loads (files &rest body) + "Execute BODY after FILES are loaded. +This macro simplifies `with-eval-after-load' for multiple nested +features." + (declare (indent 1) (debug (form def-body))) + (waterfall-list 'with-eval-after-load files body)) + +(defun waterfall-list (car list rest) + "Cons CAR with each element in LIST in a waterfall fashion, end with REST. +For use with the `with-eval-after-loads' function." + (cond ((atom list) `(,car ',list ,@rest)) + ((= 1 (length list)) `(,car ',(car list) ,@rest)) + (t + `(,car ',(car list) + ,(waterfall-list car (cdr list) rest))))) + ;;; Comment-or-uncomment-sexp ;; from https://endlessparentheses.com/a-comment-or-uncomment-sexp-command.html -- cgit 1.4.1-21-gabe81 From 7cc1e86114bfe1127f8b4698583e36162c77748b Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sat, 14 Aug 2021 18:00:12 -0500 Subject: Merge `acdw-org/count-words' and `acdw-org/count-words-stupidly' I kept the second name, because really, it is a stupid function. --- lisp/acdw-org.el | 97 +++++++++++++++++--------------------------------------- 1 file changed, 29 insertions(+), 68 deletions(-) (limited to 'lisp') diff --git a/lisp/acdw-org.el b/lisp/acdw-org.el index 189ac67..f8f23c6 100644 --- a/lisp/acdw-org.el +++ b/lisp/acdw-org.el @@ -243,74 +243,13 @@ the deletion might narrow the column." (org-table-copy-down n) (acdw-org/return-dwim n))) -(defun acdw-org/count-words (start end) - "Count words between START and END, respecting `org-mode' conventions." - (interactive (list nil nil)) - (require 'cl-lib) - (require 'ox) - (message "Counting words...") - (cond ((not (called-interactively-p 'any)) - (let ((words 0)) - (save-excursion - (save-restriction - (narrow-to-region start end) - (goto-char (point-min)) - (while (< (point) (point-max)) - (cond - ;; Ignore comments - ((or (org-at-comment-p) - (org-in-commented-heading-p)) nil) - ;; Ignore tables - ((org-at-table-p) nil) - ;; Ignore hyperlinks, but count the descriptions - ((looking-at org-bracket-link-analytic-regexp) - (when-let ((desc (match-string-no-properties 5))) - (save-match-data - (setq words (+ words - (length (remove "" - (org-split-string - desc "\\W"))))))) - (goto-char (match-end 0))) - ;; Ignore source code blocks - ((org-in-src-block-p) nil) - ;; Ignore footnotes - ((or (org-footnote-at-definition-p) - (org-footnote-at-reference-p)) - nil) - ;; else... check the context - (t (let ((contexts (org-context))) - (cond - ;; Ignore tags, TODO keywords, etc. - ((or (assoc :todo-keyword contexts) - (assoc :priority contexts) - (assoc :keyword contexts) - (assoc :checkbox contexts)) - nil) - ;; Ignore sections tagged :no-export - ((assoc :tags contexts) - (if (cl-intersection (org-get-tags-at) - org-export-exclude-tags - :test 'equal) - (org-forward-same-level 1) - nil)) - ;; else... count the word - (t (setq words (1+ words))))))) - (re-search-forward "\\w+\\W*"))) - words))) - ((use-region-p) - (message "%d words in region" - (acdw-org/count-words (region-beginning) (region-end)))) - (t - (message "%d words in buffer" - (acdw-org/count-words (point-min) (point-max)))))) - ;; This isn't the best code, but it'll do. (defun acdw-org/count-words-stupidly (start end &optional limit) "Count words between START and END, ignoring a lot. Since this function is, for some reason, pricy, the optional parameter LIMIT sets a word limit at which to stop counting. -Once the function hits that number, it'll return \"-LIMIT\" +Once the function hits that number, it'll return -LIMIT instead of the true count." (interactive (list nil nil)) (cond ((not (called-interactively-p 'any)) @@ -334,13 +273,35 @@ instead of the true count." ((or (looking-at org-drawer-regexp) (looking-at org-clock-drawer-re)) (search-forward ":END:" nil :noerror)) + ;; Ignore tables + ((org-at-table-p) (forward-line)) + ;; Ignore hyperlinks, but count the descriptions + ((looking-at org-bracket-link-analytic-regexp) + (when-let ((desc (match-string-no-properties 5))) + (save-match-data + (setq words (+ words + (length (remove "" + (org-split-string + desc "\\W"))))))) + (goto-char (match-end 0))) + ;; Ignore source blocks + ((org-in-src-block-p) (foreward-line)) ;; Count everything else - (t (setq words (1+ words)) - (if (and limit - (> words limit)) - (setq words limit - continue nil)) - (forward-word-strictly)))))) + (t + ;; ... unless it's in a few weird contexts + (let ((contexts (org-context))) + (cond ((or (assoc :todo-keyword contexts) + (assoc :priority contexts) + (assoc :keyword contexts) + (assoc :checkbox contexts)) + (forward-word-strictly)) + + (t (setq words (1+ words)) + (if (and limit + (> words limit)) + (setq words (- limit) + continue nil)) + (forward-word-strictly))))))))) words)) ((use-region-p) (message "%d words in region" -- cgit 1.4.1-21-gabe81