about summary refs log tree commit diff stats
path: root/lisp
diff options
context:
space:
mode:
authorCase Duckworth2021-05-19 22:03:24 -0500
committerCase Duckworth2021-05-19 22:03:24 -0500
commit2edbc01d872ff988508ab35cce80cc5986f3cfd2 (patch)
treeca17f364df673a718e581a202cb9fbdee90b3eb3 /lisp
parentFix typo (diff)
parentMerge branch 'main' of https://tildegit.org/acdw/emacs (diff)
downloademacs-2edbc01d872ff988508ab35cce80cc5986f3cfd2.tar.gz
emacs-2edbc01d872ff988508ab35cce80cc5986f3cfd2.zip
Merge branch 'main' of https://tildegit.org/acdw/emacs
Diffstat (limited to 'lisp')
-rw-r--r--lisp/acdw-fonts.el45
-rw-r--r--lisp/acdw-modeline.el20
-rw-r--r--lisp/acdw-org.el142
3 files changed, 122 insertions, 85 deletions
diff --git a/lisp/acdw-fonts.el b/lisp/acdw-fonts.el index 6c0cb8d..1b73af7 100644 --- a/lisp/acdw-fonts.el +++ b/lisp/acdw-fonts.el
@@ -127,5 +127,50 @@ This is for emoji fonts."
127 (set-fontset-font t 'symbol 127 (set-fontset-font t 'symbol
128 (font-spec :family font) nil 'append))))) 128 (font-spec :family font) nil 'append)))))
129 129
130
131;;; Variable-pitch
132;; from https://github.com/turbana/emacs-config#variable-pitch
133
134(defcustom acdw-fonts/fixed-pitch-faces '(linum
135 org-block
136 org-block-begin-line
137 org-block-end-line
138 org-checkbox
139 org-code
140 org-date
141 org-document-info-keyword
142 org-hide
143 org-indent
144 org-link
145 org-meta-line
146 org-special-keyword
147 org-table
148 whitespace-space)
149 "Faces to keep fixed-pitch in `acdw/variable-pitch-mode'."
150 :type 'sexp
151 :group 'faces)
152
153(defun acdw-fonts//variable-pitch-add-inherit (attrs parent)
154 "Add `:inherit PARENT' to ATTRS unless already present.
155Handles cases where `:inherit' is already specified."
156 (let ((current-parent (plist-get attrs :inherit)))
157 (unless (or (eq parent current-parent)
158 (and (listp current-parent)
159 (member parent current-parent)))
160 (plist-put attrs :inherit (if current-parent
161 (list current-parent parent)
162 parent)))))
163
164(defun acdw-fonts/adapt-variable-pitch ()
165 "Adapt `variable-pitch-mode' to keep some fonts fixed-pitch."
166 (when variable-pitch-mode
167 (mapc (lambda (face)
168 (when (facep face)
169 (apply #'set-face-attribute
170 face nil (acdw-fonts//variable-pitch-add-inherit
171 (face-attr-construct face)
172 'fixed-pitch))))
173 acdw-fonts/fixed-pitch-faces)))
174
130(provide 'acdw-fonts) 175(provide 'acdw-fonts)
131;;; acdw-fonts.el ends here 176;;; acdw-fonts.el ends here
diff --git a/lisp/acdw-modeline.el b/lisp/acdw-modeline.el index 81b808d..4f78816 100644 --- a/lisp/acdw-modeline.el +++ b/lisp/acdw-modeline.el
@@ -93,4 +93,24 @@ indicator in the mode-line."
93 (> winum--window-count 1)) 93 (> winum--window-count 1))
94 (format winum-format (winum-get-number-string)))) 94 (format winum-format (winum-get-number-string))))
95 95
96(defcustom acdw-modeline/word-count-modes
97 (mapcar (lambda (m) (cons m nil)) simple-modeline-word-count-modes)
98 "Alist of modes to functions that `acdw-modeline/word-count' should dispatch.
99If the cdr of the cons cell is nil, use the default function (`count-words').
100Otherwise, cdr should be a function that takes two points (see `count-words')."
101 :type '(alist :key-type (symbol :tag "Major-Mode")
102 :value-type function)
103 :group 'simple-modeline)
104
105(defun acdw-modeline/word-count ()
106 "Display a buffer word count, depending on the major mode.
107Uses `acdw-modeline/word-count-modes' to determine which function to use."
108 (when-let ((modefun
109 (assoc major-mode acdw-modeline/word-count-modes #'equal)))
110 (let ((fn (or (cdr modefun)
111 #'count-words))
112 (min (if (region-active-p) (region-beginning) (point-min)))
113 (max (if (region-active-p) (region-end) (point-max))))
114 (format "%dW" (funcall fn min max)))))
115
96(provide 'acdw-modeline) 116(provide 'acdw-modeline)
diff --git a/lisp/acdw-org.el b/lisp/acdw-org.el index 3f0c4ea..7e68712 100644 --- a/lisp/acdw-org.el +++ b/lisp/acdw-org.el
@@ -243,91 +243,63 @@ the deletion might narrow the column."
243 (org-table-copy-down n) 243 (org-table-copy-down n)
244 (acdw-org/return-dwim n))) 244 (acdw-org/return-dwim n)))
245 245
246(defun acdw-org/word-count (beg end 246(defun acdw-org/count-words (start end)
247 &optional count-latex-macro-args? 247 "Count words between START and END, respecting `org-mode' conventions."
248 count-footnotes?) 248 (interactive (list nil nil))
249 "Report the number of words in the Org mode buffer or selected region. 249 (cond ((not (called-interactively-p 'any))
250Ignores: 250 (let ((words 0))
251- comments 251 (save-excursion
252- tables 252 (save-restriction
253- source code blocks (#+BEGIN_SRC ... #+END_SRC, and inline blocks) 253 (narrow-to-region start end)
254- hyperlinks (but does count words in hyperlink descriptions) 254 (goto-char (point-min))
255- tags, priorities, and TODO keywords in headers 255 (while (< (point) (point-max))
256- sections tagged as 'not for export'. 256 (cond
257 ;; Ignore comments
258 ((or (org-at-comment-p)
259 (org-in-commented-heading-p)) nil)
260 ;; Ignore tables
261 ((org-at-table-p) nil)
262 ;; Ignore hyperlinks, but count the descriptions
263 ((looking-at org-bracket-link-analytic-regexp)
264 (when-let ((desc (match-string-no-properties 5)))
265 (save-match-data
266 (setq words (+ words
267 (length (remove ""
268 (org-split-string
269 desc "\\W")))))))
270 (goto-char (match-end 0)))
271 ;; Ignore source code blocks
272 ((org-in-src-block-p) nil)
273 ;; Ignore footnotes
274 ((or (org-footnote-at-definition-p)
275 (org-footnote-at-reference-p))
276 nil)
277 ;; else... check the context
278 (t (let ((contexts (org-context)))
279 (cond
280 ;; Ignore tags, TODO keywords, etc.
281 ((or (assoc :todo-keyword contexts)
282 (assoc :priority contexts)
283 (assoc :keyword contexts)
284 (assoc :checkbox contexts))
285 nil)
286 ;; Ignore sections tagged :no-export
287 ((assoc :tags contexts)
288 (if (intersection (org-get-tags-at)
289 org-export-exclude-tags
290 :test 'equal)
291 (org-forward-same-level 1)
292 nil))
293 ;; else... count the word
294 (t (setq words (1+ words)))))))
295 (re-search-forward "\\w+\\W*")))
296 words)))
297 ((use-region-p)
298 (message "%d words in region"
299 (acdw-org/count-words (region-beginning) (region-end))))
300 (t
301 (message "%d words in buffer"
302 (acdw-org/count-words (point-min) (point-max))))))
257 303
258The text of footnote definitions is ignored, unless the optional argument
259COUNT-FOOTNOTES? is non-nil.
260
261If the optional argument COUNT-LATEX-MACRO-ARGS? is non-nil, the word count
262includes LaTeX macro arguments (the material between {curly braces}).
263Otherwise, and by default, every LaTeX macro counts as 1 word regardless
264of its arguments."
265 (interactive "r")
266 (unless mark-active
267 (setf beg (point-min)
268 end (point-max)))
269 (let ((wc 0)
270 (latex-macro-regexp "\\\\[A-Za-z]+\\(\\[[^]]*\\]\\|\\){\\([^}]*\\)}"))
271 (save-excursion
272 (goto-char beg)
273 (while (< (point) end)
274 (cond
275 ;; Ignore comments.
276 ((or (org-in-commented-line) (org-at-table-p))
277 nil)
278 ;; Ignore hyperlinks. But if link has a description, count
279 ;; the words within the description.
280 ((looking-at org-bracket-link-analytic-regexp)
281 (when (match-string-no-properties 5)
282 (let ((desc (match-string-no-properties 5)))
283 (save-match-data
284 (incf wc (length (remove "" (org-split-string
285 desc "\\W")))))))
286 (goto-char (match-end 0)))
287 ((looking-at org-any-link-re)
288 (goto-char (match-end 0)))
289 ;; Ignore source code blocks.
290 ((org-in-regexps-block-p "^#\\+BEGIN_SRC\\W" "^#\\+END_SRC\\W")
291 nil)
292 ;; Ignore inline source blocks, counting them as 1 word.
293 ((save-excursion
294 (backward-char)
295 (looking-at org-babel-inline-src-block-regexp))
296 (goto-char (match-end 0))
297 (setf wc (+ 2 wc)))
298 ;; Count latex macros as 1 word, ignoring their arguments.
299 ((save-excursion
300 (backward-char)
301 (looking-at latex-macro-regexp))
302 (goto-char (if count-latex-macro-args?
303 (match-beginning 2)
304 (match-end 0)))
305 (setf wc (+ 2 wc)))
306 ;; Ignore footnotes.
307 ((and (not count-footnotes?)
308 (or (org-footnote-at-definition-p)
309 (org-footnote-at-reference-p)))
310 nil)
311 (t
312 (let ((contexts (org-context)))
313 (cond
314 ;; Ignore tags and TODO keywords, etc.
315 ((or (assoc :todo-keyword contexts)
316 (assoc :priority contexts)
317 (assoc :keyword contexts)
318 (assoc :checkbox contexts))
319 nil)
320 ;; Ignore sections marked with tags that are
321 ;; excluded from export.
322 ((assoc :tags contexts)
323 (if (intersection (org-get-tags-at) org-export-exclude-tags
324 :test 'equal)
325 (org-forward-same-level 1)
326 nil))
327 (t
328 (incf wc))))))
329 (re-search-forward "\\w+\\W*")))
330 (message (format "%d words in %s." wc
331 (if mark-active "region" "buffer")))))
332 304
333(provide 'acdw-org) 305(provide 'acdw-org)