我用Emacs 29 + org-mode记笔记,希望图片边界更明显一些,同时不造成明显卡顿就更好了。 对了,也不希望修改原始图片,希望保持原样。这样写wiki、做ppt的时候可以直接拖到对应的工具中,用工具自己的边框。

可以给 image 加个 :margin 属性( Image Descriptors ),然后改一下 face

这里简单粗暴地改了下 org-display-inline-images ,仅提供个思路。

(defun org-display-inline-images (&optional include-linked refresh beg end)
  "Display inline images.

An inline image is a link which follows either of these

  1. Its path is a file with an extension matching return value
     from `image-file-name-regexp' and it has no contents.

  2. Its description consists in a single link of the previous
     type.  In this case, that link must be a well-formed plain
     or angle link, i.e., it must have an explicit \"file\" type.

Equip each image with the key-map `image-map'.

When optional argument INCLUDE-LINKED is non-nil, also links with
a text description part will be inlined.  This can be nice for
a quick look at those images, but it does not reflect what
exported files will look like.

When optional argument REFRESH is non-nil, refresh existing
images between BEG and END.  This will create new image displays
only if necessary.

BEG and END define the considered part.  They default to the
buffer boundaries with possible narrowing."
  (interactive "P")
  (when (display-graphic-p)
    (when refresh
      (org-remove-inline-images beg end)
      (when (fboundp 'clear-image-cache) (clear-image-cache)))
    (let ((end (or end (point-max))))
      (org-with-point-at (or beg (point-min))
		(let* ((case-fold-search t)
			   (file-extension-re (image-file-name-regexp))
			   (link-abbrevs (mapcar #'car
									 (append org-link-abbrev-alist-local
			   ;; Check absolute, relative file names and explicit
			   ;; "file:" links.  Also check link abbreviations since
			   ;; some might expand to "file" links.
				(format "\\[\\[\\(?:file%s:\\|attachment:\\|[./~]\\)\\|\\]\\[\\(<?file:\\)"
						(if (not link-abbrevs) ""
						  (concat "\\|" (regexp-opt link-abbrevs))))))
		  (while (re-search-forward file-types-re end t)
			(let* ((link (org-element-lineage
						  (save-match-data (org-element-context))
						  '(link) t))
                   (linktype (org-element-property :type link))
				   (inner-start (match-beginning 1))
					 ;; No link at point; no inline image.
					 ((not link) nil)
					 ;; File link without a description.  Also handle
					 ;; INCLUDE-LINKED here since it should have
					 ;; precedence over the next case.  I.e., if link
					 ;; contains filenames in both the path and the
					 ;; description, prioritize the path only when
					 ;; INCLUDE-LINKED is non-nil.
					 ((or (not (org-element-property :contents-begin link))
					  (and (or (equal "file" linktype)
                               (equal "attachment" linktype))
						   (org-element-property :path link)))
					 ;; Link with a description.  Check if description
					 ;; is a filename.  Even if Org doesn't have syntax
					 ;; for those -- clickable image -- constructs, fake
					 ;; them, as in `org-export-insert-image-links'.
					 ((not inner-start) nil)
					  (org-with-point-at inner-start
						(and (looking-at
							  (if (char-equal ?< (char-after inner-start))
							 ;; File name must fill the whole
							 ;; description.
							 (= (org-element-property :contents-end link)
								(match-end 0))
							 (match-string 2)))))))
			  (when (and path (string-match-p file-extension-re path))
				(let ((file (if (equal "attachment" linktype)
                                  (require 'org-attach)
								  (ignore-errors (org-attach-expand path)))
                              (expand-file-name path))))
				  (when (and file (file-exists-p file))
					(let ((width (org-display-inline-image--width link))
						  (old (get-char-property-and-overlay
								(org-element-property :begin link)
					  (if (and (car-safe old) refresh)
                          (image-flush (overlay-get (cdr old) 'display))
						(let ((image (org--create-inline-image file width)))
						  (when image
							(let ((ov (make-overlay
									   (org-element-property :begin link)
										  (org-element-property :end link))
										 (skip-chars-backward " \t")
                              ;; FIXME: See bug#59902.  We cannot rely
                              ;; on Emacs to update image if the file
                              ;; has changed.
+							  (setq image (cons 'image (plist-put (cdr image) :margin 10)))
                              (image-flush image)
							  (overlay-put ov 'display image)
+							  (overlay-put ov 'face 'highlight)
-							  (overlay-put ov 'face 'default)
							  (overlay-put ov 'org-image-overlay t)
							   ov 'modification-hooks
							   (list 'org-display-inline-remove-overlay))
							  (when (boundp 'image-map)
								(overlay-put ov 'keymap image-map))
							  (push ov org-inline-image-overlays))))))))))))))))

Peek 2023-06-26 07-20

2 个赞