From 4b2e57e396314e63d70558e0aa5ad32c1cf87532 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Fri, 14 Jan 2022 17:20:23 -0600 Subject: David Bowie --- early-init.el | 31 +++++++++++++++------------- init.el | 12 ++++++----- lisp/+browse-url.el | 21 ++++++++++++------- lisp/+modeline.el | 4 +++- lisp/elephant.el | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++ lisp/remember.el | 56 --------------------------------------------------- lisp/user-save.el | 12 ++++++++--- 7 files changed, 108 insertions(+), 86 deletions(-) create mode 100644 lisp/elephant.el delete mode 100644 lisp/remember.el diff --git a/early-init.el b/early-init.el index 5a29885..c87f2df 100644 --- a/early-init.el +++ b/early-init.el @@ -90,20 +90,23 @@ See `no-littering' for examples.") :height variable-font-size))) ;; Emoji fonts - (+with-message "Adding emoji fonts" - (let ((ffl (font-family-list))) - (dolist (font '("Noto Color Emoji" - "Noto Emoji" - "Segoe UI Emoji" - "Apple Color Emoji" - "FreeSans" - "FreeMono" - "FreeSerif" - "Unifont" - "Symbola")) - (when (member font ffl) - (message "Found font: %s" font) - (set-fontset-font t 'symbol (font-spec :family font) nil :append)))))) + (+ensure-after-init + (lambda () + (+with-message "Adding emoji fonts" + (let ((ffl (font-family-list))) + (dolist (font '("Noto Color Emoji" + "Noto Emoji" + "Segoe UI Emoji" + "Apple Color Emoji" + "FreeSans" + "FreeMono" + "FreeSerif" + "Unifont" + "Symbola")) + (when (member font ffl) + (message "Found font: %s" font) + (set-fontset-font t 'symbol + (font-spec :family font) nil :append)))))))) ;;; Packages diff --git a/init.el b/init.el index 36c2bed..735ca61 100644 --- a/init.el +++ b/init.el @@ -179,11 +179,11 @@ (cond ((executable-find "mpv") #'+browse-image-with-mpv) (t #'eww-browse-url)) args))) - (cons (rx - (or "youtube.com" "youtu.be" "yewtu.be" - ;; videos + (cons (rx (or ;; videos + "youtube.com" "youtu.be" "yewtu.be" "invidious" (seq "." (or "mp4" "gif" "mov" "MOV" "webm") eos) ;; music + "soundcloud.com" "bandcamp.com" (seq "." (or "ogg" "mp3") eos))) (lambda (&rest args) (apply (if (executable-find "mpv") @@ -459,6 +459,8 @@ org-outline-path-complete-in-steps nil org-pretty-entities t org-pretty-entities-include-sub-superscripts nil + org-refile-targets '((nil . (:maxlevel . 2)) + (org-agenda-files . (:maxlevel . 1))) org-refile-use-outline-path 'file org-special-ctrl-a/e t org-special-ctrl-k t @@ -556,7 +558,7 @@ org-export-with-sub-superscripts t org-export-with-toc nil) (with-eval-after-load 'user-save - (add-hook 'org-export-before-processing-hook #'user-save-buffer))) + (advice-add 'org-export-dispatch :before 'user-save-run-hooks))) (setup prog (:local-set comment-auto-fill-only-comments t) @@ -996,7 +998,7 @@ See also `crux-reopen-as-root-mode'." elfeed-show-unique-buffers t elfeed-db-directory (elfeed/ "db/" t)) (:+key "C-x w" #'elfeed) - (advice-add #'elfeed-search-fetch :after #'beginning of buffer) + (advice-add #'elfeed-search-fetch :after #'beginning-of-buffer) (:with-mode elfeed-search-mode (:bind "&" #'+elfeed-search-browse-generic) (:hook #'hl-line-mode) diff --git a/lisp/+browse-url.el b/lisp/+browse-url.el index 89b21e4..cf0742b 100644 --- a/lisp/+browse-url.el +++ b/lisp/+browse-url.el @@ -25,7 +25,8 @@ that the latter is deprecated in Emacs 28+." (viewer default-args &optional (prompt "URL: ") &key (custom-group '+browse-url) - (name (format "+browse-url-with-%s" viewer))) + (name (format "+browse-url-with-%s" viewer)) + (fallback #'browse-url-generic)) "Create a `browse-url' handler function that calls VIEWER on the url. Also create a `customize' setting in CUSTOM-GROUP for VIEWER's arguments. DEFAULT-ARGS specifies the default arguments that @@ -33,7 +34,10 @@ setting should have. PROMPT will be shown to user in the function's `interactive' spec, as an argument to `browse-url-interactive-arg'. The resulting function will be named NAME, defaulting to \"+browse-url-with-VIEWER\", and the variable -\"NAME-args\"." +\"NAME-args\". + +If FALLBACK is non-nil, it's a function to fallback on if the +`start-process' call fails in anyway." (declare (indent 1)) `(progn (defcustom ,(intern (format "%s-args" name)) @@ -41,16 +45,19 @@ named NAME, defaulting to \"+browse-url-with-VIEWER\", and the variable ,(format "Arguments to pass to %s in `%s'." viewer name) :type '(repeat :tag "Command-line argument" string) :group ',custom-group) - (defun ,(intern name) (url &optional _new-window) + (defun ,(intern name) (url &optional new-window) ,(format "Open URL in %s." viewer) (interactive (browse-url-interactive-arg ,prompt)) (let* ((url (browse-url-encode-url url)) (process-environment (browse-url-process-environment))) (message ,(format "Opening %%s in %s..." viewer) url) - (apply #'start-process - (concat ,viewer " " url) nil - ,viewer - (append ,(intern (format "%s-args" name)) (list url))))))) + (unless (ignore-errors + (apply #'start-process + (concat ,viewer " " url) nil + ,viewer + (append ,(intern (format "%s-args" name)) + (list url)))) + (funcall fallback url new-window)))))) ;; Reference implementation: mpv (+browse-url-make-external-viewer-handler "mpv" nil "Video URL: ") diff --git a/lisp/+modeline.el b/lisp/+modeline.el index 3d7b6b7..7683269 100644 --- a/lisp/+modeline.el +++ b/lisp/+modeline.el @@ -61,7 +61,9 @@ This function makes a lambda, so you can throw it straight into "Display the buffer name." (concat (or spacer +modeline-default-spacer) (propertize - (+string-align (buffer-name) 20 :ellipsis nil) + (truncate-string-to-width (buffer-name) + (min 24 (/ (window-width) 3)) + nil ?\ t) 'help-echo (or (buffer-file-name) (buffer-name)) 'mouse-face 'mode-line-highlight))) diff --git a/lisp/elephant.el b/lisp/elephant.el new file mode 100644 index 0000000..3cae17a --- /dev/null +++ b/lisp/elephant.el @@ -0,0 +1,58 @@ +;;; elephant.el --- Remember variables and modes -*- lexical-binding: t; -*- + +;;; Code: + +(defmacro elephant-remember (alist) + "Setup a closure remembering symbols to apply with +`remember-reset'. The variables will be renamed using TEMPLATE. +ALIST contains cells of the form (SYMBOL . NEW-VALUE), where +SYMBOL is a variable or mode name, and its value is what to set +after `remember-set'." + (unless lexical-binding + (user-error "`elephant' requires lexical binding.")) + + (let* ((template (format "elephant--%s-%%s" (gensym))) + (reset-fn (intern (format template "reset")))) + (cl-destructuring-bind (let-list fn-set-list fn-reset-list) + (cl-loop + for (sym . val) in (if (symbolp alist) (symbol-value alist) alist) + as rem = (intern (format template sym)) + + collect (list rem sym) + into let-list + + collect (cond ((eq val 'enable) + `(,sym +1)) + ((eq val 'disable) + `(,sym -1)) + (t `(setq-local ,sym ,val))) + into fn-set-list + + collect (cond ((memq val '(enable disable)) + `(progn (,sym (if ,rem +1 -1)) + (fmakunbound ',rem))) + (t `(progn (setq-local ,sym ,rem) + (makunbound ',rem)))) + into fn-reset-list + + finally return (list let-list + fn-set-list + fn-reset-list)) + `(progn + (defvar-local ,reset-fn nil + "Function to recall values from `elephant-remember'.") + (let ,let-list + (setf (symbol-function ',reset-fn) + (lambda () + ,@fn-reset-list + (redraw-display) + (fmakunbound ',reset-fn)))) + ,@fn-set-list + ',reset-fn)))) + +(defun elephant-forget () + "Forget all symbols generated by `elephant-remember'." + ) + +(provide 'elephant) +;;; elephant.el ends here diff --git a/lisp/remember.el b/lisp/remember.el deleted file mode 100644 index a759419..0000000 --- a/lisp/remember.el +++ /dev/null @@ -1,56 +0,0 @@ -;;; remember.el --- Remember variables and modes -*- lexical-binding: t; -*- - -;;; Code: - -(defmacro remember-remember (alist) - (let* ((template (format "remember--%s-%%s" (gensym))) - (reset-fn (intern (format template "recall"))) - (things (cl-loop for (sym . newval) in alist - as rem = (intern (format template sym)) - - ;; Collect original values - - ))))) - - -(defmacro remember-set (&rest symbols) - "Setup a closure remembering symbols to apply with -`remember-reset'. The variables will be renamed using TEMPLATE. -SYMBOLS is a plist: the properties are symbols or mode names, and -their values what to set after `remember-setup'." - (let* ((template (format "remember--%s-%%s" (gensym))) - (reset-fn (intern (format template "reset"))) - (list (cl-loop for sym in symbols by #'cddr - collect `(,(intern (format template sym)) - ,sym) - into let-list - collect (let ((val (plist-get symbols sym))) - (cond ((eq val 'enable) - `(,sym +1)) - ((eq val 'disable) - `(,sym -1)) - (t `(setq-local ,sym ,val)))) - into fn-set-list - collect (let ((val (plist-get symbols sym)) - (rem (intern (format template sym)))) - (cond ((memq val '(enable disable)) - `(,sym (if ,rem +1 -1))) - (t `(setq-local ,sym ,rem)))) - into fn-reset-list - finally return (list let-list - fn-reset-list - fn-set-list)))) - `(progn - (defvar-local ,reset-fn nil - "Function to recall values from `remember-set'.") - (let ,(cl-first list) - (setf (symbol-function ',reset-fn) - (lambda () - ,@(cl-second list)))) - ,@(cl-third list) - ',reset-fn))) - -;; test - -(set 'fn (remember-set display-fill-column-indicator-mode disable)) -(funcall fn) diff --git a/lisp/user-save.el b/lisp/user-save.el index 63fe424..1284547 100644 --- a/lisp/user-save.el +++ b/lisp/user-save.el @@ -28,6 +28,12 @@ Emacs is killed." "Keymap for `user-save-mode'. This map shadows the default map for `save-buffer'.") +(defun user-save-run-hooks (&rest _) + "Run the hooks in `user-save-hook'. +This does /not/ also save the buffer." + (with-demoted-errors "User-save-hook error: %S" + (run-hooks 'user-save-hook))) + (defun user-save-buffer (&optional arg) "Save current buffer in visited file if modified. This function is precisely the same as `save-buffer', but with @@ -40,10 +46,10 @@ run all the time, put them in `user-save-hook'. ARG is passed directly to `save-buffer'." (interactive '(called-interactively)) - (message "Saving the buffer...") - (with-demoted-errors (run-hooks 'user-save-hook)) + (message "User-Saving the buffer...") + (user-save-run-hooks) (save-buffer arg) - (message "Saving the buffer...Done.")) + (message "User-Saving the buffer...Done.")) (defun user-save-some-buffers (&optional pred) "Save some buffers as though the user saved them. -- cgit 1.4.1-21-gabe81