From 3eeb9fb1a1a2ec814a63836ef8349d6cd71c6c5c Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Wed, 19 May 2021 10:14:02 -0500 Subject: Change `browse-url-browser-function' to alist --- init.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'init.el') diff --git a/init.el b/init.el index 06caede..d20e1ac 100644 --- a/init.el +++ b/init.el @@ -96,7 +96,8 @@ (global-auto-revert-mode +1)) (setup browse-url - (setq-default browse-url-browser-function 'eww-browse-url + (setq-default browse-url-browser-function ; can be alist (regex . function) + '(("." . eww-browse-url)) browse-url-secondary-browser-function (if (executable-find "firefox") 'browse-url-firefox -- cgit 1.4.1-21-gabe81 From 32959ca977b7b05bcbeef14c559de85ba7838243 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Wed, 19 May 2021 12:37:57 -0500 Subject: Add variable-pitch-mode in Org and Info --- init.el | 12 +++++++++++- lisp/acdw-fonts.el | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) (limited to 'init.el') diff --git a/init.el b/init.el index d20e1ac..a6e29a4 100644 --- a/init.el +++ b/init.el @@ -365,6 +365,9 @@ (setup imenu (:option imenu-auto-rescan t)) +(setup Info + (:hook variable-pitch-mode)) + (setup isearch (:option search-default-mode t)) @@ -578,6 +581,9 @@ uniquify-after-kill-buffer-p t uniquify-ignore-buffers-re "^\\*")) +(setup variable-pitch-mode + (:hook acdw-fonts/adapt-variable-pitch)) + (setup view (:option view-read-only t) @@ -936,7 +942,11 @@ if ripgrep is installed, otherwise `consult-grep'." (:bind "RET" acdw-org/return-dwim "" acdw-org/org-table-copy-down) - (add-hook 'before-save-hook #'acdw-org/fix-blank-lines-in-buffer) + (defun acdw/org-fix-lines-before-save () + (add-hook 'before-save-hook #'acdw-org/fix-blank-lines-in-buffer 0 :local)) + + (:hook variable-pitch-mode + acdw/org-fix-lines-before-save) (advice-add 'org-delete-backward-char :override #'acdw-org/delete-backward-char)) 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." (set-fontset-font t 'symbol (font-spec :family font) nil 'append))))) + +;;; Variable-pitch +;; from https://github.com/turbana/emacs-config#variable-pitch + +(defcustom acdw-fonts/fixed-pitch-faces '(linum + org-block + org-block-begin-line + org-block-end-line + org-checkbox + org-code + org-date + org-document-info-keyword + org-hide + org-indent + org-link + org-meta-line + org-special-keyword + org-table + whitespace-space) + "Faces to keep fixed-pitch in `acdw/variable-pitch-mode'." + :type 'sexp + :group 'faces) + +(defun acdw-fonts//variable-pitch-add-inherit (attrs parent) + "Add `:inherit PARENT' to ATTRS unless already present. +Handles cases where `:inherit' is already specified." + (let ((current-parent (plist-get attrs :inherit))) + (unless (or (eq parent current-parent) + (and (listp current-parent) + (member parent current-parent))) + (plist-put attrs :inherit (if current-parent + (list current-parent parent) + parent))))) + +(defun acdw-fonts/adapt-variable-pitch () + "Adapt `variable-pitch-mode' to keep some fonts fixed-pitch." + (when variable-pitch-mode + (mapc (lambda (face) + (when (facep face) + (apply #'set-face-attribute + face nil (acdw-fonts//variable-pitch-add-inherit + (face-attr-construct face) + 'fixed-pitch)))) + acdw-fonts/fixed-pitch-faces))) + (provide 'acdw-fonts) ;;; acdw-fonts.el ends here -- cgit 1.4.1-21-gabe81 From 9c6be2e953c66bbda406854797d672976877603e Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Wed, 19 May 2021 12:38:23 -0500 Subject: Setup winum keys after frame is setup I should probably change this to `after-make-frame-functions' instead... --- init.el | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) (limited to 'init.el') diff --git a/init.el b/init.el index a6e29a4..31413a4 100644 --- a/init.el +++ b/init.el @@ -1072,21 +1072,27 @@ if ripgrep is installed, otherwise `consult-grep'." (global-whitespace-cleanup-mode +1)) (setup (:straight winum) - (:option winum-auto-setup-mode-line nil + (:option winum-scope 'frame-local + winum-auto-setup-mode-line nil winum-ignored-buffers '(" *which-key*")) - (when (display-graphic-p) - (:with-map winum-keymap - (:bind "M-0" winum-select-window-0-or-10 - "M-1" winum-select-window-1 - "M-2" winum-select-window-2 - "M-3" winum-select-window-3 - "M-4" winum-select-window-4 - "M-5" winum-select-window-5 - "M-6" winum-select-window-6 - "M-7" winum-select-window-7 - "M-8" winum-select-window-8 - "M-9" winum-select-window-9))) + (when-unfocused winum-map-keys + (defvar winum--keys-mapped nil + "Whether `winum' keys have been mapped already.") + (when (and (not winum--keys-mapped) + (display-graphic-p)) + (:with-map winum-keymap + (:bind "M-0" winum-select-window-0-or-10 + "M-1" winum-select-window-1 + "M-2" winum-select-window-2 + "M-3" winum-select-window-3 + "M-4" winum-select-window-4 + "M-5" winum-select-window-5 + "M-6" winum-select-window-6 + "M-7" winum-select-window-7 + "M-8" winum-select-window-8 + "M-9" winum-select-window-9)) + (setq winum--keys-mapped t))) (winum-mode +1)) -- cgit 1.4.1-21-gabe81 From 14f6bc67ffcfb06ad4970647e660bfa05645c311 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Wed, 19 May 2021 12:39:43 -0500 Subject: Start flyspell automatically at home Free up the C-z s key for shell --- init.el | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'init.el') diff --git a/init.el b/init.el index 31413a4..09a864f 100644 --- a/init.el +++ b/init.el @@ -307,15 +307,18 @@ (unless (file-exists-p ispell-personal-dictionary) (write-region "" nil ispell-personal-dictionary nil 0)) - (defun flyspell-start () + (defun flyspell-start (&optional dont-warn-when-unknown-mode) "Start `flyspell-mode' or `flyspell-prog-mode', depending on current mode." (interactive) (cond ((derived-mode-p 'text-mode) (flyspell-mode)) ((derived-mode-p 'prog-mode) (flyspell-prog-mode)) - (t (message "Non-text or -prog mode. Run `flyspell-mode'.")))) - (:leader "s" flyspell-start) + ((not dont-warn-when-unknown-mode) ; god this is ugly + (message "Non-text or -prog mode. Run `flyspell-mode'.")))) + + (when (acdw/system :home) + (flyspell-start t)) (:when-loaded (setup (:straight flyspell-correct) -- cgit 1.4.1-21-gabe81 From 33632cc2838a20b8c77b73faa99654d31e6e21ed Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Wed, 19 May 2021 12:40:09 -0500 Subject: Add `eshell-pop-or-quit' for easier keybinding --- init.el | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'init.el') diff --git a/init.el b/init.el index 09a864f..6628b29 100644 --- a/init.el +++ b/init.el @@ -260,7 +260,8 @@ (setup eshell (:option eshell-directory-name (acdw/dir "eshell/" t) - eshell-aliases-file (acdw/dir "eshell/aliases" t)) + eshell-aliases-file (acdw/dir "eshell/aliases" t) + eshell-kill-on-exit nil) (defun eshell-quit-or-delete-char (arg) "Delete the character to the right, or quit eshell on an empty line." @@ -269,10 +270,16 @@ (eshell-life-is-too-much) (delete-forward-char arg))) - (global-set-key (kbd "") #'eshell) + (defun eshell-pop-or-quit (&optional buffer-name) + "Pop open an eshell buffer, or if in an eshell buffer, bury it." + (interactive) + (if (eq (current-buffer) (get-buffer (or buffer-name "*eshell*"))) + (eshell-life-is-too-much) + (eshell))) + + (:leader "s" eshell-pop-or-quit) (hook-defun eshell-setup 'eshell-mode-hook - (define-key eshell-mode-map (kbd "") #'bury-buffer) (define-key eshell-mode-map (kbd "C-d") #'eshell-quit-or-delete-char) (when (boundp 'simple-modeline--mode-line) (setq mode-line-format '(:eval simple-modeline--mode-line))))) -- cgit 1.4.1-21-gabe81 From bdc2c3c40e3cd394416dabad55d94ac5fc0016b6 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Wed, 19 May 2021 12:40:53 -0500 Subject: Remove unused variables IDK --- init.el | 6 ------ 1 file changed, 6 deletions(-) (limited to 'init.el') diff --git a/init.el b/init.el index 6628b29..0d0284d 100644 --- a/init.el +++ b/init.el @@ -113,12 +113,6 @@ (setup completion (:option completion-ignore-case t read-buffer-completion-ignore-case t - icomplete-delay-completions-threshold 0 - icomplete-max-delay-chars 0 - icomplete-compute-delay 0 - icomplete-show-matches-on-no-input t - icomplete-with-buffer-completion-tables t - icomplete-in-buffer t completion-styles '(partial-completion substring flex) completion-category-defaults nil completion-category-overrides -- cgit 1.4.1-21-gabe81 From f8198ee81445476c8053bdfcd964d6d0ce5bd252 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Wed, 19 May 2021 12:41:16 -0500 Subject: Add Firefox to exec-path /before/ checking if it's available --- init.el | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'init.el') diff --git a/init.el b/init.el index 0d0284d..6058eef 100644 --- a/init.el +++ b/init.el @@ -96,16 +96,17 @@ (global-auto-revert-mode +1)) (setup browse-url + (when (acdw/system :work) + (add-to-list 'exec-path "C:/Program Files/Mozilla Firefox")) + (setq-default browse-url-browser-function ; can be alist (regex . function) '(("." . eww-browse-url)) browse-url-secondary-browser-function - (if (executable-find "firefox") + (if (executable-find "firefox") ; prefer Firefox 'browse-url-firefox 'browse-url-default-browser) browse-url-new-window-flag t - browse-url-firefox-new-window-is-tab t) - (when (acdw/system :work) - (add-to-list 'exec-path "C:/Program Files/Mozilla Firefox"))) + browse-url-firefox-new-window-is-tab t)) (setup buffers (:global "C-x k" acdw/kill-a-buffer)) -- cgit 1.4.1-21-gabe81 From bb07f08067b0a4be7b480fc11bfef5a8c654556d Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Wed, 19 May 2021 12:55:12 -0500 Subject: Configure shell-command From http://www.nextpoint.se/?p=864 --- init.el | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'init.el') diff --git a/init.el b/init.el index 6058eef..17fac5b 100644 --- a/init.el +++ b/init.el @@ -569,6 +569,14 @@ (:hook flymake-mode flymake-shellcheck-load))) +(setup shell-command + (:option shell-command-switch (acdw/system + ;; I should be testing on some variable + (:home "-csi") + (:work "-c")) + shell-command-prompt-show-cwd t + shell-command-default-error-buffer "*shell-command-errors*")) + (setup shr (:option shr-width fill-column shr-max-width fill-column -- cgit 1.4.1-21-gabe81 From 66d0e6999cf3bd1bb45d5e121f2d1168e0c8a846 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Wed, 19 May 2021 15:28:58 -0500 Subject: Rewrite acdw-modeline/word-count to show region counts --- init.el | 27 ++++++++++++++------------- lisp/acdw-modeline.el | 20 ++++++++++++++++++++ 2 files changed, 34 insertions(+), 13 deletions(-) (limited to 'init.el') diff --git a/init.el b/init.el index 06caede..b8584b6 100644 --- a/init.el +++ b/init.el @@ -972,19 +972,20 @@ if ripgrep is installed, otherwise `consult-grep'." (setup (:straight simple-modeline) (setup (:straight minions)) - (:option simple-modeline-segments - '((acdw-modeline/modified - acdw-modeline/buffer-name - acdw-modeline/vc-branch - simple-modeline-segment-position - simple-modeline-segment-word-count) - (simple-modeline-segment-misc-info - acdw-modeline/winum - acdw-modeline/text-scale - simple-modeline-segment-process - acdw-modeline/god-mode-indicator - acdw-modeline/minions - simple-modeline-segment-major-mode))) + (:option + ;; (prepend acdw-modeline/word-count-modes) '(org-mode . #'acdw-org/word-count) + simple-modeline-segments '((acdw-modeline/modified + acdw-modeline/buffer-name + acdw-modeline/vc-branch + simple-modeline-segment-position) + (simple-modeline-segment-misc-info + acdw-modeline/word-count + acdw-modeline/winum + acdw-modeline/text-scale + simple-modeline-segment-process + acdw-modeline/god-mode-indicator + acdw-modeline/minions + simple-modeline-segment-major-mode))) (require 'acdw-modeline) (simple-modeline-mode +1)) 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." (> winum--window-count 1)) (format winum-format (winum-get-number-string)))) +(defcustom acdw-modeline/word-count-modes + (mapcar (lambda (m) (cons m nil)) simple-modeline-word-count-modes) + "Alist of modes to functions that `acdw-modeline/word-count' should dispatch. +If the cdr of the cons cell is nil, use the default function (`count-words'). +Otherwise, cdr should be a function that takes two points (see `count-words')." + :type '(alist :key-type (symbol :tag "Major-Mode") + :value-type function) + :group 'simple-modeline) + +(defun acdw-modeline/word-count () + "Display a buffer word count, depending on the major mode. +Uses `acdw-modeline/word-count-modes' to determine which function to use." + (when-let ((modefun + (assoc major-mode acdw-modeline/word-count-modes #'equal))) + (let ((fn (or (cdr modefun) + #'count-words)) + (min (if (region-active-p) (region-beginning) (point-min))) + (max (if (region-active-p) (region-end) (point-max)))) + (format "%dW" (funcall fn min max))))) + (provide 'acdw-modeline) -- cgit 1.4.1-21-gabe81 From ccf03a4be3ee88110d35818dffcd88517c1d1787 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Wed, 19 May 2021 17:06:32 -0500 Subject: Change definition of `acdw-org/count-words' (I renamed it from `acdw-org/word-count'.) It's still too slow for use in the modeline. So I have work to do still... --- init.el | 3 +- lisp/acdw-org.el | 142 ++++++++++++++++++++++--------------------------------- 2 files changed, 59 insertions(+), 86 deletions(-) (limited to 'init.el') diff --git a/init.el b/init.el index b8584b6..3bec384 100644 --- a/init.el +++ b/init.el @@ -973,7 +973,8 @@ if ripgrep is installed, otherwise `consult-grep'." (setup (:straight simple-modeline) (setup (:straight minions)) (:option - ;; (prepend acdw-modeline/word-count-modes) '(org-mode . #'acdw-org/word-count) + ;; `acdw-org/count-words' is too slow to use in the modeline. + ;; (prepend acdw-modeline/word-count-modes) '(org-mode . acdw-org/count-words) simple-modeline-segments '((acdw-modeline/modified acdw-modeline/buffer-name acdw-modeline/vc-branch 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." (org-table-copy-down n) (acdw-org/return-dwim n))) -(defun acdw-org/word-count (beg end - &optional count-latex-macro-args? - count-footnotes?) - "Report the number of words in the Org mode buffer or selected region. -Ignores: -- comments -- tables -- source code blocks (#+BEGIN_SRC ... #+END_SRC, and inline blocks) -- hyperlinks (but does count words in hyperlink descriptions) -- tags, priorities, and TODO keywords in headers -- sections tagged as 'not for export'. +(defun acdw-org/count-words (start end) + "Count words between START and END, respecting `org-mode' conventions." + (interactive (list nil nil)) + (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 (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)))))) -The text of footnote definitions is ignored, unless the optional argument -COUNT-FOOTNOTES? is non-nil. - -If the optional argument COUNT-LATEX-MACRO-ARGS? is non-nil, the word count -includes LaTeX macro arguments (the material between {curly braces}). -Otherwise, and by default, every LaTeX macro counts as 1 word regardless -of its arguments." - (interactive "r") - (unless mark-active - (setf beg (point-min) - end (point-max))) - (let ((wc 0) - (latex-macro-regexp "\\\\[A-Za-z]+\\(\\[[^]]*\\]\\|\\){\\([^}]*\\)}")) - (save-excursion - (goto-char beg) - (while (< (point) end) - (cond - ;; Ignore comments. - ((or (org-in-commented-line) (org-at-table-p)) - nil) - ;; Ignore hyperlinks. But if link has a description, count - ;; the words within the description. - ((looking-at org-bracket-link-analytic-regexp) - (when (match-string-no-properties 5) - (let ((desc (match-string-no-properties 5))) - (save-match-data - (incf wc (length (remove "" (org-split-string - desc "\\W"))))))) - (goto-char (match-end 0))) - ((looking-at org-any-link-re) - (goto-char (match-end 0))) - ;; Ignore source code blocks. - ((org-in-regexps-block-p "^#\\+BEGIN_SRC\\W" "^#\\+END_SRC\\W") - nil) - ;; Ignore inline source blocks, counting them as 1 word. - ((save-excursion - (backward-char) - (looking-at org-babel-inline-src-block-regexp)) - (goto-char (match-end 0)) - (setf wc (+ 2 wc))) - ;; Count latex macros as 1 word, ignoring their arguments. - ((save-excursion - (backward-char) - (looking-at latex-macro-regexp)) - (goto-char (if count-latex-macro-args? - (match-beginning 2) - (match-end 0))) - (setf wc (+ 2 wc))) - ;; Ignore footnotes. - ((and (not count-footnotes?) - (or (org-footnote-at-definition-p) - (org-footnote-at-reference-p))) - nil) - (t - (let ((contexts (org-context))) - (cond - ;; Ignore tags and TODO keywords, etc. - ((or (assoc :todo-keyword contexts) - (assoc :priority contexts) - (assoc :keyword contexts) - (assoc :checkbox contexts)) - nil) - ;; Ignore sections marked with tags that are - ;; excluded from export. - ((assoc :tags contexts) - (if (intersection (org-get-tags-at) org-export-exclude-tags - :test 'equal) - (org-forward-same-level 1) - nil)) - (t - (incf wc)))))) - (re-search-forward "\\w+\\W*"))) - (message (format "%d words in %s." wc - (if mark-active "region" "buffer"))))) (provide 'acdw-org) -- cgit 1.4.1-21-gabe81