From dd3afe747ecf51f87d33318c2ad68953d153495f Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Mon, 23 May 2022 20:12:53 -0500 Subject: meh --- lisp/+avy.el | 60 ++++++++++++++++++++++++++++++++++++++++++++++++ lisp/+emacs.el | 6 ++--- lisp/+modeline.el | 6 ++--- lisp/+org-drawer-list.el | 12 +++++++--- lisp/+org-wc.el | 29 +++++++++++++++++------ lisp/+org.el | 2 +- lisp/+pdf-tools.el | 38 ++++++++++++++++++++++++++++++ lisp/+scratch.el | 25 ++++++++++++++++---- lisp/+titlecase.el | 26 +++++++++++++++++++++ lisp/acdw.el | 26 +++++++++++++++------ 10 files changed, 201 insertions(+), 29 deletions(-) create mode 100644 lisp/+pdf-tools.el create mode 100644 lisp/+titlecase.el (limited to 'lisp') diff --git a/lisp/+avy.el b/lisp/+avy.el index 5010e95..0606405 100644 --- a/lisp/+avy.el +++ b/lisp/+avy.el @@ -17,5 +17,65 @@ (cdr (ring-ref avy-ring 0)))) t) + +;;; Remove `buffer-face-mode' when avy is active. + +(defcustom +avy-buffer-face-functions '(avy-goto-char + avy-goto-char-in-line + avy-goto-char-2 + avy-goto-char-2-above + avy-goto-char-2-below + avy-goto-word-0 + avy-goto-whitespace-end + avy-goto-word-0-above + avy-goto-word-0-below + avy-goto-whitespace-end-above + avy-goto-whitespace-end-below + avy-goto-word-1 + avy-goto-word-1-above + avy-goto-word-1-below + avy-goto-symbol-1 + avy-goto-symbol-1-above + avy-goto-symbol-1-below + avy-goto-subword-0 + avy-goto-subword-1 + avy-goto-word-or-subword-1 + avy-goto-line + avy-goto-line-above + avy-goto-line-below + avy-goto-end-of-line + avy-goto-char-timer) + "Functions to disable `buffer-face-mode' during.") + +(defvar-local +avy-buffer-face-mode-face nil + "The state of `buffer-face-mode' before calling `avy-with'.") + +(defun +avy@un-buffer-face (&rest _) + "BEFORE advice on `avy-with' to disable `buffer-face-mode'." + (when buffer-face-mode + (setq +avy-buffer-face-mode-face buffer-face-mode-face) + (buffer-face-mode -1))) + +(defun +avy@re-buffer-face (&rest _) + "AFTER advice on `avy-with' to re-enable `buffer-face-mode'." + (when +avy-buffer-face-mode-face + (setq buffer-face-mode-face +avy-buffer-face-mode-face) + (buffer-face-mode +1))) + +(define-minor-mode +avy-buffer-face-local-mode + "Turn off `buffer-face-mode' before doing Avy selections. +Restore the mode after the selection." + :lighter "" + :global t + (setq +avy-buffer-face-mode-face nil) + (cond + (+avy-buffer-face-mode + (dolist (fn +avy-buffer-face-functions) + (advice-add fn :before #'+avy@un-buffer-face)) + (advice-add 'avy--done :after #'+avy@re-buffer-face)) + (t (dolist (fn +avy-buffer-face-functions) + (advice-remove fn #'+avy@un-buffer-face)) + (advice-remove 'avy--done #'+avy@re-buffer-face)))) + (provide '+avy) ;;; avy.el ends here diff --git a/lisp/+emacs.el b/lisp/+emacs.el index 3c5d383..dedde98 100644 --- a/lisp/+emacs.el +++ b/lisp/+emacs.el @@ -73,8 +73,6 @@ Do this only if the buffer is not visiting a file." (executable-find "gm") (executable-find "ffmpeg")) indent-tabs-mode nil - indicate-buffer-boundaries 'left - indicate-empty-lines nil inhibit-startup-screen t initial-buffer-choice t kept-new-versions 6 @@ -98,9 +96,11 @@ Do this only if the buffer is not visiting a file." native-comp-deferred-compilation nil read-answer-short t read-buffer-completion-ignore-case t - ;; read-extended-command-predicate (when (fboundp + ;; read-extended-command-predicate + ;; (when (fboundp ;; 'command-completion-default-include-p) ;; 'command-completion-default-include-p) + read-process-output-max (+bytes 1 :mib) ; We’re in the future man. Set that to at least a megabyte recenter-positions '(top middle bottom) regexp-search-ring-max 100 regexp-search-ring-max 200 diff --git a/lisp/+modeline.el b/lisp/+modeline.el index 86dbad4..2c9bbee 100644 --- a/lisp/+modeline.el +++ b/lisp/+modeline.el @@ -393,9 +393,9 @@ to a function in the current buffer, call that function instead." ;; adapted from https://github.com/seagle0128/doom-modeline (when (and (boundp 'text-scale-mode-amount) (/= text-scale-mode-amount 0)) - (format (if (> text-scale-mode-amount 0) "%s(%+d)" "%s(%-d)") - (or spacer +modeline-default-spacer) - text-scale-mode-amount))) + (+modeline-spacer nil spacer + (concat (if (> text-scale-mode-amount 0) "+" "-") + (number-to-string text-scale-mode-amount))))) (defun +modeline-ace-window-display (&optional spacer) "Display `ace-window-display-mode' information in the modeline." diff --git a/lisp/+org-drawer-list.el b/lisp/+org-drawer-list.el index 2fc7234..5066d4d 100644 --- a/lisp/+org-drawer-list.el +++ b/lisp/+org-drawer-list.el @@ -26,7 +26,7 @@ format the list item as an Org link." "mailto"))) (current-kill 0)) (string-trim (current-kill 0)) - (read-string "URL: "))) + (read-string "Resource URL: "))) (url-title (let ((clipboard-headings (+org-insert--get-title-and-headings clipboard-url))) (read-string "title (edit): " @@ -34,8 +34,14 @@ format the list item as an Org link." "title: " clipboard-headings nil nil nil nil (car clipboard-headings)))))) (list clipboard-url url-title))) - (org-drawer-list-add +org-drawer-list-resources-drawer - (org-link-make-string url title))) + (let (current-visible-mode visible-mode) + ;; XXX: This is not the "proper" way to fix the issue I was having --- I've + ;; isolated the bug to somewhere in `org-insert-item', but this fix works + ;; well enough™ for now. + (visible-mode +1) + (org-drawer-list-add +org-drawer-list-resources-drawer + (org-link-make-string url title)) + (visible-mode (if current-visible-mode +1 -1)))) (provide '+org-drawer-list) ;;; +org-drawer-list.el ends here diff --git a/lisp/+org-wc.el b/lisp/+org-wc.el index 7ab0050..edd88f0 100644 --- a/lisp/+org-wc.el +++ b/lisp/+org-wc.el @@ -19,8 +19,7 @@ (defcustom +org-wc-update-after-funcs '(org-narrow-to-subtree org-narrow-to-block org-narrow-to-element - org-capture-narrow - org-taskwise-narrow-to-task) + org-capture-narrow) "Functions after which to update the word count." :type '(repeat function)) @@ -32,6 +31,16 @@ "Number of characters that constitute a \"huge\" insertion." :type 'number) +(defcustom +org-wc-huge-buffer 10000 + "Number of words past which we're not going to try to count." + :type 'number) + +(defvar +org-wc-correction -5 + "Number to add to `+org-wc-word-count', for some reason? +`+org-wc-word-count' seems to consistently be off by 5. Thus +this correction. (At some point I should correct the underlying +code... probably).") + (defvar-local +org-wc-update-timer nil) (defun +org-wc-delayed-update (&rest _) @@ -48,7 +57,7 @@ (+org-wc-update) (message "Counting words...done")) -(defun +org-wc-update () +(defun +org-wc-update (&rest _) ; Needs variadic parameters, since it's advice (dlet ((+org-wc-counting t)) (+org-wc-buffer) (force-mode-line-update) @@ -59,9 +68,14 @@ (defun +org-wc-buffer () "Count the words in the buffer." - (when (derived-mode-p 'org-mode) + (when (and (derived-mode-p 'org-mode) + (not (eq +org-wc-word-count 'huge))) (setq +org-wc-word-count - (org-word-count-aux (point-min) (point-max))))) + (cond + ((> (count-words (point-min) (point-max)) + +org-wc-huge-buffer) + 'huge) + (t (org-word-count-aux (point-min) (point-max))))))) (defvar +org-wc-counting nil "Are we currently counting?") @@ -71,8 +85,9 @@ (+org-wc-update))) (defun +org-wc-modeline () - (when +org-wc-word-count - (format " %sw" +org-wc-word-count))) + (cond + ((eq +org-wc-word-count 'huge) "huge") + (+org-wc-word-count (format " %sw" (max 0 (+ +org-wc-word-count +org-wc-correction)))))) (define-minor-mode +org-wc-mode "Count words in `org-mode' buffers in the mode-line." diff --git a/lisp/+org.el b/lisp/+org.el index 89ed483..6b93a7a 100644 --- a/lisp/+org.el +++ b/lisp/+org.el @@ -669,7 +669,7 @@ and POST-PROCESS are passed to `org-export-to-file'." "Advice to run `org-mode-hook' when entering org-mode. This should only fire when switching to a buffer from `org-agenda'." (unless +org-hook-has-run-p - (run-hooks 'org-mode-hook) + (run-mode-hooks 'org-mode-hook) (setq +org-hook-has-run-p t))) (define-minor-mode +org-agenda-inhibit-hooks-mode diff --git a/lisp/+pdf-tools.el b/lisp/+pdf-tools.el new file mode 100644 index 0000000..9b15b27 --- /dev/null +++ b/lisp/+pdf-tools.el @@ -0,0 +1,38 @@ +;;; +pdf-tools.el --- Extras for the excellent pdf-tools' -*- lexical-binding: t; -*- + +;;; Commentary: + +;;; Code: + +;; XXX: The way I'm dispatching browsers here is /very/ down-and-dirty. It +;; needs to be much improved. + +(defun +pdf-view-open-all-pagelinks (&optional browse-url-func) + "Open all the links on this page of a PDF. +BROWSE-URL-FUNC overrides the default `browse-url'." + (interactive) + (let ((links (pdf-info-pagelinks (pdf-view-current-page))) + (browse-url-func (or browse-url-func #'browse-url)) + (seen)) + (dolist (link links) + (when-let* ((uri (alist-get 'uri link)) + (_ (not (member uri seen)))) + (push uri seen) + (funcall browse-url-func uri))))) + +(defun +pdf-view-open-links-in-chrome () + "Open all links on this PDF page in Chrome. +See also `+pdf-view-open-all-pagelinks'." + (interactive) + (+pdf-view-open-all-pagelinks #'browse-url-chrome)) + +(defun +pdf-view-position (&optional spacer) + "Return the page we're on for the modeline." + (when (derived-mode-p 'pdf-view-mode) + (format "%sp.%s/%s" + (or spacer (bound-and-true-p +modeline-default-spacer) " ") + (pdf-view-current-page) + (pdf-info-number-of-pages)))) + +(provide '+pdf-tools) +;;; +pdf-tools.el ends here diff --git a/lisp/+scratch.el b/lisp/+scratch.el index e9b825a..7fc2bde 100644 --- a/lisp/+scratch.el +++ b/lisp/+scratch.el @@ -35,18 +35,33 @@ For `kill-buffer-query-functions'." "ABANDON ALL HOPE YE WHO ENTER HERE")))) (concat (replace-regexp-in-string "^" ";; " s) "\n\n"))) - + ;; [[https://old.reddit.com/r/emacs/comments/ui1q41/weekly_tips_tricks_c_thread/i7ef4xg/][u/bhrgunatha]] (defun +scratch-text-scratch () "Create a \"*text*\" scratch buffer in Text mode." (with-current-buffer (get-buffer-create "*text*") (text-mode))) +(defcustom +scratch-buffers '("*text*" "*scratch*") + "Scratch buffers.") + +(defvar +scratch-last-non-scratch-buffer nil + "Last buffer that wasn't a scratch buffer.") + (defun +scratch-toggle (buffer) - "Switch to BUFFER, or to the previous buffer." - (switch-to-buffer (unless (eq (current-buffer) - (get-buffer buffer)) - buffer))) + "Switch to BUFFER, or to the previous (non-scratch) buffer." + (if (or (null +scratch-last-non-scratch-buffer) + (not (member (buffer-name (current-buffer)) +scratch-buffers))) + ;; Switch to a scratch buffer + (progn + (setq +scratch-last-non-scratch-buffer (current-buffer)) + (switch-to-buffer buffer)) + ;; Switch away from scratch buffer ... + (if (equal (get-buffer-create buffer) (current-buffer)) + ;; to the original buffer + (switch-to-buffer +scratch-last-non-scratch-buffer) + ;; to another scratch + (switch-to-buffer buffer)))) (defun +scratch-switch-to-scratch () "Switch to scratch buffer." diff --git a/lisp/+titlecase.el b/lisp/+titlecase.el new file mode 100644 index 0000000..1366a46 --- /dev/null +++ b/lisp/+titlecase.el @@ -0,0 +1,26 @@ +;;; +titlecase.el --- Titlecase extras -*- lexical-binding: t; -*- + +;;; Commentary: + +;;; Code: + +(defun +titlecase-sentence-style-dwim () + "Titlecase a sentence." + (interactive) + (titlecase-dwim 'sentence)) + +(defun +titlecase-org-headings () + (interactive) + (save-excursion + (goto-char (point-min)) + ;; See also `org-map-tree'. I'm not using that function because I want to + ;; skip the first headline. A better solution would be to patch + ;; `titlecase-line' to ignore org-mode metadata (TODO cookies, tags, etc). + (let ((level (funcall outline-level))) + (while (and (progn (outline-next-heading) + (> (funcall outline-level) level)) + (not (eobp))) + (titlecase-line))))) + +(provide '+titlecase) +;;; +titlecase.el ends here diff --git a/lisp/acdw.el b/lisp/acdw.el index 9b3ab93..191cdfb 100644 --- a/lisp/acdw.el +++ b/lisp/acdw.el @@ -282,7 +282,8 @@ always nil; this function is mostly intended for use in init." (defcustom chat-functions '(+irc jabber-connect-all - slack-start) + ;; slack-start + ) "Functions to start when calling `chat'." :type '(repeat function) :group 'applications) @@ -292,16 +293,17 @@ always nil; this function is mostly intended for use in init." (interactive) (+with-progress "Quitting circe..." (ignore-errors - (circe-command-GQUIT "☮ 🫀 🍞") + (circe-command-GQUIT "peace love bread") (cancel-timer (irc-connection-get conn :flood-timer)))) (+with-progress "Quitting jabber..." (ignore-errors (jabber-disconnect))) - (+with-progress "Quitting-slack..." - (dolist (team +slack-teams) - (ignore-errors - (slack-team-disconnect team))) - (ignore-errors (slack-ws-close))) + (when (boundp '+slack-teams) + (+with-progress "Quitting-slack..." + (dolist (team +slack-teams) + (ignore-errors + (slack-team-disconnect team))) + (ignore-errors (slack-ws-close)))) (+with-progress "Killing buffers..." (ignore-errors (+mapc-some-buffers (lambda () "Remove the buffer from tracking and kill it unconditionally." @@ -496,6 +498,9 @@ sort order." (lambda () (message "%S-second timer DONE!" secs) (setq +timer-string +timer-done-string) + (let ((visible-bell t) + (ring-bell-function nil)) + (ding)) (ding)))))) (defun +timer-cancel () @@ -508,5 +513,12 @@ sort order." (message "Timer canceled."))) (setq +timer-string nil)) + + +(defun +switch-to-last-buffer () + "Switch to the last-used buffer in this window." + (interactive) + (switch-to-buffer nil)) + (provide 'acdw) ;;; acdw.el ends here -- cgit 1.4.1-21-gabe81