软换行 or 硬换行?大家的使用习惯是什么?

经过多种权衡,我最终决定语义换行搭配各种论坛上找到的导出自动处理空格的函数。

https://emacs-china.org/t/org-mode-html/7174

只需要稍微修改一下就可以给 markdown 导出使用。

(define-advice org-gfm-paragraph
    (:around (orig-fun paragraph contents info) org-gfm-paragraph-advice)
  "Join consecutive Chinese lines into a single long line without
unwanted space when exporting org-mode to html."
  (let* ((fix-regexp "[[:multibyte:]]")
         (fixed-contents
          (replace-regexp-in-string
           (concat
            "\\(" fix-regexp "\\) *\n *\\(" fix-regexp "\\)") "\\1\\2" contents)))
    (funcall orig-fun paragraph fixed-contents info)))


updated

我发现对于我这个强迫症患者,面对使用语义换行导致的每行文字长度的不一致, 可以换一个角度说服自己。 语义换行根据文字意群换行,文字长度错落有致,像诗一样。 把文字根据语义安排好换行的顺序,真的让我感觉到很舒服。

但是语义换行其实有时候很难受。比如一个包含了对比或转折的句子, 一开始写的时候,想写的不长,于是决定放在一行, 但是写到转折的部分突然想要扩充一下,这个时候一个句子分成两行更合适。 但写作的时候写到一半,移动光标到前一个标点符号、删除、返回, 这个操作很烦人。 于是我写了这个新的函数绑定到 M-q, 在前面最近的一个标点符号之后进行换行。



(defun my/newline-after-punctuation ()
  "在光标前最近的标点符号后换行,但保持光标相对于文本的位置不变。"
  (interactive)
  (let ((punct-regexp "[,。;?!,.;?!]"))
    (save-excursion
      (if (re-search-backward punct-regexp nil t)
          (progn
            (forward-char 1)
            (newline-and-indent))
        (message "前面未找到标点符号"))))) 
3 个赞