aboutsummaryrefslogtreecommitdiff
path: root/emacs/.emacs.d/lisp/my
diff options
context:
space:
mode:
authorYuchen Pei <id@ypei.org>2023-09-07 23:15:32 +1000
committerYuchen Pei <id@ypei.org>2023-09-07 23:15:32 +1000
commit6ec968e2cadca7e4df4aba8960e758aa6c7d00b0 (patch)
treec080d4738f61eb0ed32258da56f528292a79e65c /emacs/.emacs.d/lisp/my
parent1622ac38772868d101e48107591db8f4700627c4 (diff)
[emacs] Some small enhancement
Remove empty blocks automatically. When org-insert-structure-template, with a prefix, auto yank into block and exit
Diffstat (limited to 'emacs/.emacs.d/lisp/my')
-rw-r--r--emacs/.emacs.d/lisp/my/my-gnus.el3
-rw-r--r--emacs/.emacs.d/lisp/my/my-org.el28
2 files changed, 25 insertions, 6 deletions
diff --git a/emacs/.emacs.d/lisp/my/my-gnus.el b/emacs/.emacs.d/lisp/my/my-gnus.el
index 1f7ff18..9c42204 100644
--- a/emacs/.emacs.d/lisp/my/my-gnus.el
+++ b/emacs/.emacs.d/lisp/my/my-gnus.el
@@ -339,7 +339,8 @@ The archiving target comes from `my-gnus-group-alist'."
url)
pairs))
(while (and (shr-next-link)
- (<= (point) end))
+ (<= (point) end)
+ (button-at (point)))
(let ((button (button-at (point))))
(push (cons (buffer-substring-no-properties
(button-start button)
diff --git a/emacs/.emacs.d/lisp/my/my-org.el b/emacs/.emacs.d/lisp/my/my-org.el
index 43be91f..03b34ff 100644
--- a/emacs/.emacs.d/lisp/my/my-org.el
+++ b/emacs/.emacs.d/lisp/my/my-org.el
@@ -79,13 +79,25 @@ With a prefix, insert inactive dates.
"A :before advice for org-edit-src-exit."
(delete-trailing-whitespace))
+(defun my-org-element-block-p (element)
+ "Returns t if ELEMENT is an org block."
+ (memq (org-element-type element)
+ '(center-block comment-block dynamic-block
+ example-block export-block quote-block
+ special-block src-block verse-block)))
+
(defun my-org-edit-src-after-exit ()
"An :after advice for org-edit-src-exit.
-Deactivate mark and move point to after the block."
+If the block is empty, remove it.
+Otherwise deactivate mark and move point to after the block."
(deactivate-mark)
- (re-search-forward "^[ \t]*#\\+end_")
- (beginning-of-line 2))
+ (let ((element (org-element-at-point)))
+ (cl-assert (my-org-element-block-p element))
+ (if (string-empty-p (org-element-property :value element))
+ (delete-region (org-element-property :begin element)
+ (org-element-property :end element))
+ (goto-char (org-element-property :end element)))))
;; navigation
(defun my-org-jump-to-last-visible-child ()
@@ -1252,13 +1264,19 @@ Flush lines with only some common symbols."
(interactive "p")
(my-org-vote-up (- points)))
-;; used to add advice to `org-insert-structure-template'.
+;; used to add an :after advice to `org-insert-structure-template'.
(require 'my-buffer)
(defun my-org-edit-special (type)
+ "Choose mode if src block. Then enter edit special
+
+With a prefix arg, yank and exit immediately."
(when (equal type "src")
(insert (string-remove-suffix
"-mode" (prin1-to-string (my-read-major-mode)))))
- (org-edit-special))
+ (org-edit-special)
+ (when current-prefix-arg
+ (yank)
+ (org-edit-src-exit)))
(defun my-link-to-line-number-in-prog-mode ()
"When in prog-mode, use line number as search item."