From 9360a54e6208c87911530ea8005b626680fa2e88 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Fri, 7 Jan 2022 17:30:46 -0600 Subject: Gah, so many changes --- lisp/+init.el | 50 +++++++++++++++++++++------------------- lisp/+org.el | 74 ++++++++++++++++++++++++++++++++++++++++++----------------- lisp/acdw.el | 19 +++++++-------- 3 files changed, 89 insertions(+), 54 deletions(-) (limited to 'lisp') diff --git a/lisp/+init.el b/lisp/+init.el index 360a1b9..c1f3cb5 100644 --- a/lisp/+init.el +++ b/lisp/+init.el @@ -37,41 +37,43 @@ are sorted lexigraphically." nil ;; Sort function (lambda (s1 s2) - (let ((s1 (cdr s1)) (s2 (cdr s2))) - (cond + (let ((s1 (cdr s1)) (s2 (cdr s2))) + (cond ;; Sort everything /not/ `setup' /before/ `setup' ((and (+init--sexp-setup-p s1) - (not (+init--sexp-setup-p s2))) + (not (+init--sexp-setup-p s2))) nil) ((and (+init--sexp-setup-p s2) - (not (+init--sexp-setup-p s1))) + (not (+init--sexp-setup-p s1))) t) ;; otherwise... (t (let ((s1-straight (+init--sexp-setup-p s1 :straight)) (s2-straight (+init--sexp-setup-p s2 :straight)) (s1-require (+init--sexp-setup-p s1 :require)) (s2-require (+init--sexp-setup-p s2 :require))) - (cond - ;; `:straight' setups have extra processing - ((and s1-straight s2-straight) - (let* ((r (rx (: ":straight" (? "-when") (* space) (? "(")))) - (s1 (replace-regexp-in-string r "" s1)) - (s2 (replace-regexp-in-string r "" s2))) + (cond + ;; `:straight' setups have extra processing + ((and s1-straight s2-straight) + (let* ((r (rx (: ":straight" (? "-when") (* space) (? "(")))) + (s1 (replace-regexp-in-string r "" s1)) + (s2 (replace-regexp-in-string r "" s2))) (string< s1 s2))) - ;; `:require' setups go first - ((and s1-require (not s2-require)) t) - ((and s2-require (not s1-require)) nil) - ;; `:straight' setups go last - ((and s1-straight (not s2-straight)) nil) - ((and s2-straight (not s1-straight)) t) - ;; otherwise, sort lexigraphically - (t (string< s1 s2)))))))))))) + ;; `:require' setups go first + ((and s1-require (not s2-require)) t) + ((and s2-require (not s1-require)) nil) + ;; `:straight' setups go last + ((and s1-straight (not s2-straight)) nil) + ((and s2-straight (not s1-straight)) t) + ;; otherwise, sort lexigraphically + (t (string< s1 s2)))))))))))) (defun +init-sort-then-save () "Sort init.el, then save it." (interactive) (+init-sort) - (save-buffer)) + (if (fboundp #'user-save-buffer) + (user-save-buffer) + (save-buffer))) ;;; Add `setup' forms to `imenu-generic-expression' @@ -79,11 +81,11 @@ are sorted lexigraphically." "Recognize `setup' forms in `imenu'." ;; `imenu-generic-expression' automatically becomes buffer-local when set (setf (alist-get "Setup" imenu-generic-expression nil nil 'string-equal) - (list - (rx (: bol (* space) - "(setup" (+ space) - (group (? "(") (* nonl)))) - 1))) + (list + (rx (: bol (* space) + "(setup" (+ space) + (group (? "(") (* nonl)))) + 1))) ;;; Major mode diff --git a/lisp/+org.el b/lisp/+org.el index fc1caea..090af5a 100644 --- a/lisp/+org.el +++ b/lisp/+org.el @@ -253,9 +253,9 @@ instead of the true count." ;;; org-insert-link-dwim - https://xenodium.com/emacs-dwim-do-what-i-mean/ -(defun +org-insert-link-dwim () +(defun +org-insert-link-dwim (&optional interactivep) "Like `org-insert-link' but with personal dwim preferences." - (interactive) + (interactive '(t)) (let* ((point-in-link (org-in-regexp org-link-any-re 1)) (clipboard-url (when (string-match-p (rx (sequence bos @@ -266,25 +266,30 @@ instead of the true count." (current-kill 0))) (region-content (when (region-active-p) (buffer-substring-no-properties (region-beginning) - (region-end))))) - (cond ((and region-content clipboard-url (not point-in-link)) - (delete-region (region-beginning) (region-end)) - (insert (org-link-make-string clipboard-url region-content))) - ((and clipboard-url (not point-in-link)) - (insert (org-link-make-string - clipboard-url - (read-string "title: " - (with-current-buffer - (url-retrieve-synchronously - clipboard-url) - (dom-text - (car - (dom-by-tag (libxml-parse-html-region - (point-min) - (point-max)) - 'title)))))))) - (t - (call-interactively 'org-insert-link))))) + (region-end)))) + (org-link (when clipboard-url + (org-link-make-string + clipboard-url + (or region-content + (read-string "title: " + (with-current-buffer + (url-retrieve-synchronously + clipboard-url) + (dom-text + (car + (dom-by-tag (libxml-parse-html-region + (point-min) + (point-max)) + 'title)))))))))) + (if interactivep + (cond ((and region-content clipboard-url (not point-in-link)) + (delete-region (region-beginning) (region-end)) + (insert org-link)) + ((and clipboard-url (not point-in-link)) + (insert org-link)) + (t + (call-interactively 'org-insert-link))) + org-link))) ;;; Navigate headings with widening @@ -409,5 +414,32 @@ the deletion might narrow the column." (dotimes (_ fill-column) (insert "-"))) +;; Follow links, DWIM style + +(defun +org-open-at-point-dwim (&optional arg) + "Open thing at point, or if there isn't something, list things." + (interactive "P") + (save-excursion + (let* ((this-char-type (org-element-type (org-element-context))) + (prev-char-type (save-excursion + (backward-char) + (org-element-type (org-element-context)))) + (types '(citation citation-reference clock comment comment-block + footnote-definition footnote-reference headline + inline-src-block inlinetask keyword link + node-property planning src-block timestamp)) + (type this-char-type)) + (when (and (memq this-char-type types) (memq prev-char-type types)) + (backward-char) + (setq type prev-char-type)) ; what the fuckckckckck + (if (memq type types) + (progn (org-open-at-point arg)) + (while (not + (progn + (org-back-to-heading) + (car (org-offer-links-in-entry (current-buffer) (point) 1)))) + (org-up-heading-all 1)) + (org-open-at-point arg))))) + (provide '+org) ;;; +org.el ends here diff --git a/lisp/acdw.el b/lisp/acdw.el index 9361cdf..262c15e 100644 --- a/lisp/acdw.el +++ b/lisp/acdw.el @@ -143,7 +143,7 @@ within a `with-current-buffer' form." (let ((pred (or predicate t))) (dolist (buf (buffer-list)) (with-current-buffer buf - (when (funcall pred buf) + (when (if (fboundp pred) (funcall pred buf) pred) (funcall func)))))) ;; https://github.com/cstby/emacs.d/blob/main/init.el#L67 @@ -176,14 +176,15 @@ surrounded by empty lines, so opening a paragraph means to make three blank lines, then place the point on the second one." (interactive "*") (unless (derived-mode-p 'special-mode 'lui-mode 'comint-mode) - ;; Go to next blank line. This /isn't/ `end-of-paragraph-text' because - ;; that's weird with org, and I'm guessing other modes too. - (while (not (looking-at "^$")) - (forward-line 1)) - (newline) - (delete-blank-lines) - (newline 2) - (previous-line))) + ;; Go to next blank line. This /isn't/ `end-of-paragraph-text' because + ;; that's weird with org, and I'm guessing other modes too. + (while (and (not (looking-at "^$")) + (< (point) (point-max))) + (forward-line 1)) + (newline) + (delete-blank-lines) + (newline 2) + (previous-line))) (defun +split-window-then (&optional where arg) "Split the window into a new buffer. -- cgit 1.4.1-21-gabe81