Compare commits

...

6 Commits

Author SHA1 Message Date
Case Duckworth 57f0dd43c4 bleh 2022-04-27 08:38:03 -05:00
Case Duckworth 0b573c7eba Add functions for org
These aren't bound or implemented but they're here in case I want them.
2022-04-27 08:37:11 -05:00
Case Duckworth 4b1eaab205 Add +org-show-mode
Toggle org-hide-emphasis-markers and org-link display
2022-04-27 08:36:35 -05:00
Case Duckworth 8edc3aa615 Also inhibit user-save-mode with predicates 2022-04-27 08:35:48 -05:00
Case Duckworth 340c8583cc Display fortunes in scratch buffer 2022-04-27 08:35:22 -05:00
Case Duckworth 3f925fc0e3 Add +org-export-pre-hook to prepare the buffer before export 2022-04-24 17:00:36 -05:00
6 changed files with 209 additions and 37 deletions

109
init.el
View File

@ -55,6 +55,8 @@
line-number-minor-tick
line-number-current-line))
(:face face '((t (:inherit fixed-pitch)))))
(:face 'font-lock-comment-face '((t ( :inherit variable-pitch
:slant italic))))
;; Hooks
(add-hook 'prog-mode-hook #'turn-on-auto-fill)
(add-hook 'prog-mode-hook #'font-lock-todo-insinuate)
@ -732,9 +734,13 @@
org-agenda-file-regexp
org-agenda-templates))
(add-to-list '+custom-variable-allowlist var))
(define-advice org-agenda-files (:filter-return (ret))
"Remove SyncThing's sync-conflict files from the org agenda."
(seq-remove (lambda (f) (string-match-p "sync-conflict" f)) ret))
(:+leader "a" #'org-agenda "C-a" #'org-agenda)
(:hook #'hl-line-mode)
(add-hook 'org-agenda-after-show-hook 'org-narrow-to-subtree))
(:local-set truncate-lines t)
(add-hook 'org-agenda-after-show-hook #'org-narrow-to-subtree))
(setup org-attach
(:also-load +org-attach)
@ -796,7 +802,8 @@
org-attach-id-uuid-folder-format)))
(setup ox ; org-export
(:also-load ox-md)
(:also-load +ox
ox-md)
(:option org-export-coding-system 'utf-8-unix
org-export-headline-levels 8
org-export-with-drawers nil
@ -804,8 +811,11 @@
org-export-with-smart-quotes t
org-export-with-sub-superscripts t
org-export-with-toc nil)
(with-eval-after-load 'ox
(+org-export-pre-hooks-insinuate))
(add-hook '+org-export-pre-hook #'+flyspell-correct-buffer)
(with-eval-after-load 'user-save
(advice-add 'org-export-as :before #'user-save-run-hooks)))
(add-hook '+org-export-pre-hook #'user-save-run-hooks)))
(setup password-cache
(:option password-cache t
@ -821,12 +831,7 @@
(setup scratch
(:require +scratch)
(:option initial-major-mode #'lisp-interaction-mode
initial-scratch-message
(concat (replace-regexp-in-string "^" ";; "
(string-trim (if (executable-find "fortune")
(shell-command-to-string "fortune -s")
"ABANDON ALL HOPE YE WHO ENTER HERE")))
"\n\n"))
initial-scratch-message (+scratch-fortune))
(add-hook 'kill-buffer-query-functions #'+scratch-immortal))
(setup shr
@ -923,8 +928,8 @@ They are completed by \"M-x TAB\" only in Tramp debug buffers."
(setq affe-regexp-compiler (defun affe-orderless-regexp-compiler (input &rest _)
(setq input (orderless-pattern-compiler input))
(cons input (lambda (str) (orderless--highlight input str)))))
(setf (alist-get 'affe-grep vertico-multiform-commands) '(buffer)
(alist-get 'affe-find vertico-multiform-commands) '(buffer))
(setf (alist-get 'affe-grep vertico-multiform-commands) nil
(alist-get 'affe-find vertico-multiform-commands) nil)
(:+key "M-s g" #'affe-grep
"M-s f" #'affe-find)))
@ -1019,6 +1024,13 @@ They are completed by \"M-x TAB\" only in Tramp debug buffers."
(with-eval-after-load 'notifications
(add-hook 'bongo-player-metadata-changed-hook #'+bongo-notify)))
(setup (:straight browse-kill-ring)
(:+key "C-M-y" #'browse-kill-ring)
(:option browse-kill-ring-highlight-current-entry t
browse-kill-ring-highlight-inserted-item 'pulse
browse-kill-ring-separator " ")
(:hook #'form-feed-mode))
(setup (:straight (cape
:host github :repo "minad/cape"))
(dolist (fn
@ -1326,7 +1338,7 @@ They are completed by \"M-x TAB\" only in Tramp debug buffers."
consult-imenu
consult-imenu-multi
consult-outline))
(setf (alist-get buf-cmd vertico-multiform-commands) '(buffer))))))
(setf (alist-get buf-cmd vertico-multiform-commands) nil)))))
(setup (:straight consult-dir)
(:+key "C-x C-d" #'consult-dir)
@ -1337,8 +1349,8 @@ They are completed by \"M-x TAB\" only in Tramp debug buffers."
(setup (:straight consult-notmuch)
(:load-after consult notmuch)
(with-eval-after-load 'vertico-multiform
(setf (alist-get 'consult-notmuch vertico-multiform-commands) '(buffer)
(alist-get 'consult-notmuch-tree vertico-multiform-commands) '(buffer))))
(setf (alist-get 'consult-notmuch vertico-multiform-commands) nil
(alist-get 'consult-notmuch-tree vertico-multiform-commands) nil)))
(setup (:straight corfu
:quit "Turns out, I actually like minibuffer completion better.")
@ -1497,7 +1509,8 @@ See also `crux-reopen-as-root-mode'."
(file+olp ,(car rmh-elfeed-org-files) "Feeds")
"* %? %^g")))
(setup (:straight elpher))
(setup (:straight elpher)
(:bind "l" #'elpher-back))
(setup (:straight embark)
(:require embark
@ -1629,6 +1642,8 @@ See also `crux-reopen-as-root-mode'."
forge-gitea-repository)))
(setup (:straight form-feed)
;; See also `page-break-lines', further down.
(:face 'form-feed-line '((t (:strike-through t))))
(global-form-feed-mode +1))
(setup (:straight (frowny
@ -1680,7 +1695,12 @@ See also `crux-reopen-as-root-mode'."
describe-function describe-variable
helpful-function helpful-macro helpful-callable
helpful-variable))
(setf (alist-get cmd vertico-multiform-commands) nil))))
(setf (alist-get cmd vertico-multiform-commands) nil)))
;; Load faster on first invocation by pre-loading a slow function
;; (see https://github.com/Wilfred/helpful/issues/236)
(run-with-idle-timer 1 nil (lambda ()
(require 'info-look)
(info-lookup-setup-mode 'symbol 'emacs-lisp-mode))))
(setup (:straight (hippie-completing-read
:host github
@ -1749,25 +1769,32 @@ See also `crux-reopen-as-root-mode'."
"jabber-fallback-lib/hexrgb.el"
"jabber-fallback-lib/srv.el"
"jabber-fallback-lib/fsm.el")
"jabber-pkg.el")))
"jabber-pkg.el")
:fork ( :host nil
:repo "https://codeberg.org/acdw/emacs-jabber")))
(:also-load +jabber)
(defvar +jabber-ws-prefix 8 "Width to pad left side of chats.")
(defvar +jabber-ws-prefix 0 "Width to pad left side of chats.")
(defvar +jabber-pre-prompt " \n"
"String to show before a prompt.")
(:option jabber-account-list '(("acdw@hmm.st"))
jabber-groupchat-buffer-format "X:%n"
jabber-chat-buffer-format "X:%n"
jabber-muc-private-buffer-format "X:%n(%g)"
jabber-groupchat-buffer-format "%n"
jabber-chat-buffer-format "%n"
jabber-muc-private-buffer-format "%n(%g)"
jabber-activity-show-p #'ignore
jabber-muc-decorate-presence-patterns
'(("\\( enters the room ([^)]+)\\| has left the chatroom\\)$")
("." . jabber-muc-presence-dim))
jabber-muc-colorize-foreign t
jabber-chat-foreign-prompt-format (concat "[%t] %n:\n"
jabber-chat-foreign-prompt-format (concat +jabber-pre-prompt
"[%t] %n\n"
(make-string +jabber-ws-prefix
?\ ))
jabber-chat-local-prompt-format (concat "[%t] %n:\n"
jabber-chat-local-prompt-format (concat +jabber-pre-prompt
"[%t] %n\n"
(make-string +jabber-ws-prefix
?\ ))
jabber-groupchat-prompt-format (concat "[%t] %n:\n"
jabber-groupchat-prompt-format (concat +jabber-pre-prompt
"[%t] %n\n"
(make-string +jabber-ws-prefix
?\ ))
jabber-auto-reconnect t)
@ -1776,20 +1803,28 @@ See also `crux-reopen-as-root-mode'."
(modus-themes-with-colors
(:face 'jabber-chat-prompt-foreign `((t (:foreground ,red)))
'jabber-chat-prompt-local `((t (:foreground ,blue)))
'jabber-chat-prompt-system `((t (:foreground ,green)))))))
'jabber-chat-prompt-system `((t (:foreground ,green)))))
(setq jabber-muc-nick-value (pcase (frame--current-backround-mode (selected-frame))
('light 0.5)
('dark 1.0)))
(+mapc-some-buffers #'+jabber-colors-update
(lambda () (derived-mode-p 'jabber-chat-mode
'jabber-roster-mode
'jabber-activity-mode
'jabber-browse-mode)))))
(dolist (mode '(jabber-chat-mode
jabber-browse-mode
jabber-roster-mode
jabber-console-mode))
(add-hook (intern (format "%s-hook" mode)) #'visual-fill-column-mode))
(let ((hook (intern (format "%s-hook" mode))))
(add-hook hook #'visual-fill-column-mode)))
(add-hook 'jabber-activity-mode-hook #'tracking-mode)
(:with-mode jabber-chat-mode
(:local-set +modeline-position-function (lambda ()
(cond
((string-match-p "hmm@" (buffer-name))
"🤔 ")))
wrap-prefix (make-string +jabber-ws-prefix ?\ )
))
wrap-prefix (make-string +jabber-ws-prefix ?\ )))
(:+leader "C-j" jabber-global-keymap)
(advice-add 'jabber-activity-add :after #'+jabber-tracking-add)
(advice-add 'jabber-activity-add-muc :after #'+jabber-tracking-add-muc))
@ -1929,9 +1964,8 @@ See also `crux-reopen-as-root-mode'."
(:face 'modus-themes-tab-active '((t :bold nil))
'modus-themes-tab-inactive '((t :italic t)))
;; Fix a "nil is not a Modus theme" error
;; XXX: Need to register a bug report
(define-advice modus-themes--current-theme (:around (fn &rest r))
"Fix a \"nil is not a Modus theme\" error."
(or (apply fn r)
'modus-operandi))
@ -1992,6 +2026,10 @@ See also `crux-reopen-as-root-mode'."
:quit "Buggy")
(:load-after notmuch))
(setup (:straight nov)
(:hook #'visual-fill-column-mode)
(:file-match (rx ".epub" eos)))
(setup (:straight ol-notmuch))
(setup (:straight orderless)
@ -2041,7 +2079,8 @@ See also `crux-reopen-as-root-mode'."
(setup (:straight org-modern)
(:option org-modern-hide-stars nil
org-modern-star nil
org-modern-list nil)
org-modern-list nil
org-modern-progress ["..." "o.." "oo." "Oo." "Ooo" "OOo" "OOO"])
(:face 'org-modern-label '((t ( :height 1.0
:weight regular
:underline nil
@ -2075,6 +2114,10 @@ See also `crux-reopen-as-root-mode'."
;; Remove it from init.el files
(add-hook '+init-mode-hook #'flymake-mode-off))
(setup (:straight page-break-lines)
(:option page-break-lines-char ?—)
(:hook-into jabber-chat-mode))
(setup (:straight paredit)
(:also-load +paredit)
(:bind "DEL" #'paredit-backward-delete
@ -2345,7 +2388,7 @@ See also `crux-reopen-as-root-mode'."
(setf (alist-get 'completion-at-point vertico-multiform-commands) '(flat))
(setf (alist-get 'indent-for-tab-command vertico-multiform-commands) '(flat))
(setf (alist-get 'insert-char vertico-multiform-commands) nil)
(setf (alist-get 'file vertico-multiform-categories) '(buffer))
(setf (alist-get 'file vertico-multiform-categories) nil)
(setf (alist-get 'bookmark vertico-multiform-categories) nil)
;; Default. Needs to be `add-to-list' so that it appears at the end.
(add-to-list 'vertico-multiform-categories '(t flat) :append)
@ -2417,6 +2460,8 @@ See also `crux-reopen-as-root-mode'."
(:also-load +xkcd)
(:hook #'visual-fill-column-mode))
(setup (:straight xr))
(setup (:straight yaoddmuse))
(setup (:straight yasnippet)

View File

@ -250,5 +250,17 @@ associated face. Ignore notification if face is nil."
(buffer-string))
:time (current-time))))))))))))
(defun +jabber-colors-update (&optional buffer)
"Update jabber colors in BUFFER, defaulting to the current."
(with-current-buffer (or buffer (current-buffer))
(when jabber-buffer-connection
(setq jabber-muc-participant-colors nil)
(cond (jabber-chatting-with
(jabber-chat-create-buffer jabber-buffer-connection
jabber-chatting-with))
(jabber-group
(jabber-muc-create-buffer jabber-buffer-connection
jabber-group))))))
(provide '+jabber)
;;; +jabber.el ends here

View File

@ -588,5 +588,66 @@ and POST-PROCESS are passed to `org-export-to-file'."
("" "---"))))
(replace-match replace nil nil)))))
;;; Toggle org-hide-emphasis-markers
(define-minor-mode +org-show-mode
"Show emphasis markers and full links in `org-mode'."
:lighter "/*/"
(setq org-hide-emphasis-markers (not +org-show-mode)
org-link-descriptive (not +org-show-mode))
(funcall (if +org-show-mode
#'remove-from-invisibility-spec
#'add-to-invisibility-spec)
'(org-link))
(font-lock-update))
;;; go forward and backward in the tree, ~ cleanly ~
;; https://stackoverflow.com/a/25201697/10756297
(defun +org-show-next-heading-tidily ()
"Show next entry, keeping other entries closed."
(interactive)
(if (save-excursion (end-of-line) (outline-invisible-p))
(progn (org-show-entry) (show-children))
(outline-next-heading)
(unless (and (bolp) (org-on-heading-p))
(org-up-heading-safe)
(hide-subtree)
(user-error "Boundary reached"))
(org-overview)
(org-reveal t)
(org-show-entry)
(recenter-top-bottom)
(show-children)
(recenter-top-bottom 1)))
(defun +org-show-previous-heading-tidily ()
"Show previous entry, keeping other entries closed."
(interactive)
(let ((pos (point)))
(outline-previous-heading)
(unless (and (< (point) pos) (bolp) (org-on-heading-p))
(goto-char pos)
(hide-subtree)
(user-error "Boundary reached"))
(org-overview)
(org-reveal t)
(org-show-entry)
(recenter-top-bottom)
(show-children)
(recenter-top-bottom 1)))
;;; Make `org-flag-region' (which folds subtrees) recognize
;; [[https://teddit.net/r/orgmode/comments/u3du0v/how_to_make_orgcycle_respect_and_always_show_the/][from u/yantar92]]
;; (advice-add 'org-flag-region :around #'org-flag-region@unfold-page-breaks)
(defun org-flag-region@unfold-page-breaks (oldfun from to flag &optional spec)
"ADVICE to unfold all the page-break lines inside a folded region."
(funcall oldfun from to flag spec)
(when (and flag (not (eq 'visible spec)))
(org-with-point-at from
(while (re-search-forward "\n\u000c\n" to t)
(org-flag-region (match-beginning 0) (match-end 0) t 'visible)))))
(provide '+org)
;;; +org.el ends here

29
lisp/+ox.el Normal file
View File

@ -0,0 +1,29 @@
;;; +ox.el --- org-export helpers -*- lexical-binding: t; -*-
;;; Commentary:
;;; Code:
(require 'ox)
;;; Run hooks before doing any exporting at all
(defcustom +org-export-pre-hook nil
"Functions to run /before/ `org-export-as' does anything.
These will run on the buffer about to be exported, NOT a copy."
:type 'hook)
(defun +org-export-pre-run-hooks (&rest _)
"Run hooks in `+org-export-pre-hook'."
(run-hooks '+org-export-pre-hook))
(defun +org-export-pre-hooks-insinuate ()
"Advise `org-export-as' to run `+org-export-pre-hook'."
(advice-add 'org-export-as :before #'+org-export-pre-run-hooks))
(defun +org-export-pre-hooks-remove ()
"Remove pre-hook advice on `org-export-as'."
(advice-remove 'org-export-as #'+org-export-pre-run-hooks))
(provide '+ox)
;;; +ox.el ends here

View File

@ -24,5 +24,16 @@ For `kill-buffer-query-functions'."
(next-line 2))
(rename-buffer (concat "*scratch<" mode ">*") t)))
(defun +scratch-fortune ()
(let* ((fmt (if (executable-find "fmt")
(format "| fmt -%d -s" (- fill-column 2))
""))
(s (string-trim
(if (executable-find "fortune")
(shell-command-to-string (concat "fortune -s" fmt))
"ABANDON ALL HOPE YE WHO ENTER HERE"))))
(concat (replace-regexp-in-string "^" ";; " s)
"\n\n")))
(provide '+scratch)
;;; +scratch.el ends here

View File

@ -29,10 +29,16 @@ This option is only useful is `user-save-mode' is active when
Emacs is killed."
:type 'boolean)
(defcustom user-save-inhibit '(special-mode)
(defcustom user-save-inhibit-modes '(special-mode)
"List of modes to inhibit `user-save-mode' from activation in."
:type '(repeat symbol))
(defcustom user-save-inhibit-predicates '(user-save-non-file-buffer-p)
"List of predicates to inhibit `user-save-mode' from activation.
Each predicate will be called with no arguments, and if it
returns t, will inhibit `user-save-mode' from activating."
:type '(repeat function))
(defvar user-save-hook nil
"Hook to run when the user, not Emacs, saves the buffer.")
@ -47,7 +53,13 @@ This map shadows the default map for `save-buffer'.")
"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)))
(run-hooks 'user-save-hook)))
(defun user-save-non-file-buffer-p (&optional buffer-or-name)
"Return whether BUFFER-OR-NAME is a non-file buffer.
BUFFER-OR-NAME, if omitted, defaults to the current buffer."
(with-current-buffer (or buffer-or-name (current-buffer))
(not (buffer-file-name))))
(defun user-save-buffer (&optional arg)
"Save current buffer in visited file if modified.
@ -99,9 +111,11 @@ whether the buffer needs to be saved."
(defun user-save-mode-in-some-buffers ()
"Enable `user-save-mode', but only in some buffers.
The mode will not be enabled in buffers derived from modes in
`user-save-inhibit', or in the minibuffer."
(unless (or (cl-some #'derived-mode-p user-save-inhibit)
(minibufferp))
`user-save-inhibit-modes', those for which
`user-save-inhibit-predicates' return t, or in the minibuffer."
(unless (or (minibufferp)
(cl-some #'derived-mode-p user-save-inhibit-modes)
(run-hook-with-args-until-failure 'user-save-inhibit-predicates))
(user-save-mode +1)))
;;;###autoload