让Org mode显示不一样的markup

Org mode里~code~=verbatim=用得很多,但是这两个markup看起来不如markdown的`。我想要把~=都显示成`,这样好看一点。看了下Org的代码,没法干净地修改着色行为,只好把整个函数拿出来重新定义了一下。

效果:

代码:

(with-eval-after-load 'org
  (setq org-emphasis-alist
        '(("*" bold)
          ("/" italic)
          ("_" underline)
          ("=" org-verbatim verbatim (display "`"))
          ("~" org-code verbatim (display "`"))
          ("+"
           (:strike-through t))))

  (defun org-do-emphasis-faces (limit)
    "Run through the buffer and emphasize strings."
    (let ((quick-re (format "\\([%s]\\|^\\)\\([~=*/_+]\\)"
			    (car org-emphasis-regexp-components))))
      (catch :exit
        (while (re-search-forward quick-re limit t)
	  (let* ((marker (match-string 2))
	         (verbatim? (member marker '("~" "="))))
	    (when (save-excursion
		    (goto-char (match-beginning 0))
		    (and
		     ;; Do not match table hlines.
		     (not (and (equal marker "+")
			       (org-match-line
			        "[ \t]*\\(|[-+]+|?\\|\\+[-+]+\\+\\)[ \t]*$")))
		     ;; Do not match headline stars.  Do not consider
		     ;; stars of a headline as closing marker for bold
		     ;; markup either.
		     (not (and (equal marker "*")
			       (save-excursion
			         (forward-char)
			         (skip-chars-backward "*")
			         (looking-at-p org-outline-regexp-bol))))
		     ;; Match full emphasis markup regexp.
		     (looking-at (if verbatim? org-verbatim-re org-emph-re))
		     ;; Do not span over paragraph boundaries.
		     (not (string-match-p org-element-paragraph-separate
					  (match-string 2)))
		     ;; Do not span over cells in table rows.
		     (not (and (save-match-data (org-match-line "[ \t]*|"))
			       (string-match-p "|" (match-string 4))))))
              ;; beg
	      (pcase-let ((`(,_ ,face ,_ ,props) (assoc marker org-emphasis-alist)))
                ;; end
	        (font-lock-prepend-text-property
	         (match-beginning 2) (match-end 2) 'face face)
	        (when verbatim?
		  (org-remove-flyspell-overlays-in
		   (match-beginning 0) (match-end 0))
		  (remove-text-properties (match-beginning 2) (match-end 2)
					  '(display t invisible t intangible t)))
	        (add-text-properties (match-beginning 2) (match-end 2)
				     '(font-lock-multiline t org-emphasis t))
                ;; beg
                (when props
                  (add-text-properties (match-end 4) (match-beginning 5)
				       props)
                  (add-text-properties (match-beginning 3) (match-end 3)
				       props))
                ;; end
	        (when org-hide-emphasis-markers
		  (add-text-properties (match-end 4) (match-beginning 5)
				       '(invisible org-link))
		  (add-text-properties (match-beginning 3) (match-end 3)
				       '(invisible org-link)))
	        (throw :exit t)))))))))
2 个赞

还可以试试把这些符号隐藏起来:(setq org-hide-emphasis-marks t)

藏起来的话编辑起来太痛苦。

如果只是编辑里面的文本应该还好。我也是前两天才知道这个选项,在尝试怎么用着舒服

负责地告诉你,很痛苦。

隐藏起来确实不如显示好用,尤其是插入链接之类的时候。

应该是 (setq org-hide-emphasis-markers t)

1 个赞

看下org-appear,可以让你既美观又消除痛苦。

1 个赞