用org-toggle-inline-images
显示Org文档的图片时,如果图片过多,会明显感觉到卡顿,因此我写了个小函数来只切换当前subtree下的图片。
(defun org-display-subtree-inline-images ()
"Toggle the display of inline images.
INCLUDE-LINKED is passed to `org-display-inline-images'."
(interactive)
(save-excursion
(save-restriction
(org-narrow-to-subtree)
(let* ((beg (point-min))
(end (point-max))
(image-overlays (cl-intersection
org-inline-image-overlays
(overlays-in beg end))))
(if image-overlays
(progn
(org-remove-inline-images)
(message "Inline image display turned off"))
(org-display-inline-images t t beg end)
(setq image-overlays (cl-intersection
org-inline-image-overlays
(overlays-in beg end)))
(if (and (org-called-interactively-p) image-overlays)
(message "%d images displayed inline"
(length image-overlays))))))))
还有,有时候需要调换相邻图片链接的位置,下面的两个函数可以提供该功能。
(defun org-move-link-left ()
"Move link at point to left."
(interactive)
(let ((point (point))
(eop (org-element-context)))
(when (eq 'link (car eop))
(let* ((start (org-element-property :begin eop))
(end (org-element-property :end eop))
(contents (buffer-substring start end)))
(goto-char start)
(skip-chars-backward "[ \t]+")
(let ((leop (org-element-context)))
(if (eq 'link (car leop))
(let* ((left-start (org-element-property :begin leop))
(left-end (org-element-property :end leop))
(left-contents (buffer-substring left-start left-end)))
(setf (buffer-substring start end) left-contents)
(setf (buffer-substring left-start left-end)
(if (= (org-element-property :post-blank eop) 0)
(concat contents " ")
contents))
(goto-char (+ left-start (- point start))))
(message "No link found on the left")))))))
(add-hook 'org-metaleft-hook #'org-move-link-left)
(defun org-move-link-right ()
"Move link at point to right."
(interactive)
(let ((point (point))
(eop (org-element-context)))
(when (eq 'link (car eop))
(let* ((start (org-element-property :begin eop))
(end (org-element-property :end eop))
(contents (buffer-substring start end)))
(goto-char end)
(skip-chars-forward "[ \t]+")
(let ((reop (org-element-context)))
(if (eq 'link (car reop))
(let* ((right-start (org-element-property :begin reop))
(right-end (org-element-property :end reop))
(blanks (org-element-property :post-blank reop))
(right-contents (buffer-substring right-start right-end)))
(setf (buffer-substring right-start right-end) contents)
(setf (buffer-substring start end) right-contents)
;; (org-display-subtree-inline-images)
(goto-char (+ point (- right-end right-start))))
(message "No link found on the right")))))))
(add-hook 'org-metaright-hook #'org-move-link-right)