中英文混排时候的自动折行?

emacs中算第几列时,一个中文字符等于两个英文占的列数,怎么把它改成一对一呢?

挺有意思的问题,但跟这个主题没关,你应该单独开个新主题。

org mode 的确默认不折行,但是你可以在你的配置中加上这段代码:

(setq org-startup-truncated t)

其实我很喜欢emacs的truncate-linne,从实践中发现wrap实在太难受,尤其在orgmode的时候,影响结构观感。只有在必须的时候自己toggle-truncate-line就好了,大多数时候就如楼上所说使用手动段落切割 M-q

一般如果需要恢复段落的原始长行,可以使用如下函数(我无耻的抄的):

;; ** Set unfill function

(defun your-specific-config-name/unfill-paragraph (&optional region)
  "Takes a multi-line paragraph and makes it into a single line of text."
  (interactive (progn (barf-if-buffer-read-only) '(t)))
  (let ((fill-column (point-max))
	;; This would override `fill-column' if it's an integer.
	(emacs-lisp-docstring-fill-column t))
    (fill-paragraph nil region)))

对于Markdown, org, latex, 同不建议写超长行。

有传说中的爷爷一样老的auto-fill mode可以用,设个舒服的fill-column的值(每行最多字数),比如80,到了超出你点空白字符键时就会自动加回车换行。当你进行插入或者删除等修改操作后,变得各行不齐时,在当前段落任何位置,按下M-q就又重新排齐啦。

我是被老板安利的,主要这玩意儿太老了,除非看书,根本不会注意到。我之前衣纠结过很久,知道用了它。我写长邮件草稿都用Emacs了,为了换行和对齐方便。

另附上把自动换行对齐为多个行在段落重新转成一个超长行:

;; unfill paragraph: the opposite of fill-paragraph
(defun y:unfill-paragraph-or-region (&optional region)
  "Takes a multi-line paragraph and makes it into a single line of text."
  (interactive (progn (barf-if-buffer-read-only) '(t)))
  (let ((fill-column (point-max))
        ;; This would override `fill-column' if it's an integer.
        (emacs-lisp-docstring-fill-column t))
    (fill-paragraph nil region)))
(define-key global-map "\M-Q" 'y:unfill-paragraph-or-region)
1 个赞

网上有看到一个方法,可以保持 jk 正常在虚拟行中移动,而不会整段地移动;同时去掉了换行处的标志。在 dotspacemacs/user-config 加入:

  (defun org-line-wrap ()
    (spacemacs/toggle-visual-line-navigation-on)
    (setq-local word-wrap nil))
  (add-hook 'org-mode-hook 'org-line-wrap)

将上面的 nil 改为 t,则每一段换行后是完整的单词。

Org mode 能导出富文本的邮件

1 个赞

求教 怎么到处富文本邮件,我查看输出列表里没有啊? 好神奇呀,好想知道 :joy:

M-x org-mime-org-buffer-htmlize, 需要 org-mime 包。

1 个赞

我也是换行的忠实支持者,但觉得 auto-fill-mode 不够用,所以用的 aggressive-fill-paragraph-mode

1 个赞

好的,在这里 如何改变中文字符宽度

This has been fixed in Emacs 28. You can now say (setq word-wrap-by-category t) to make Emacs respect kinsoku rules when wrapping lines visually.

挖个坟,今天读这个链接发现这个问题在 Emacs 28 中被修复了,native-comp 也适用,感叹一下,好棒啊!

9 个赞

问一下,中英文混排时自动拆行,这个在org的表格里面能用吗?

比如,我这个贴子里面 org-mode超链接文件的打开方式 org-file-apps - #2,来自 wsug 自动生成的表格,我控制了文件名称这一列为显示40个英文字符,20个中文(一个中文算2个英文字符),超出40个英文字符自动折行。但这个是后端生成org表格时写死的(用php的mb_strimwidth和mb_strwidth函数判断)

如果能用表格自动布满当前emacs窗口,超长行拆行(而不是显示…),这样和html的table就更像了

你好,你的org的配色和bullet图标很好看。请问是怎么实现的?

這個圖裡面沒有英語單詞啊,怎麼說明能夠解決主題的呢?我的也是28版,但仍有中英文折行不合理的問題。

2 个赞

GNU Emacs 29.0.60 (build 1, aarch64-apple-darwin22.2.0, NS appkit-2299.30 Version 13.1 (Build 22C65)) of 2023-01-12

测试文字:

make Emacs respect kinsoku rules when wrapp這個圖裡面沒有英語單詞啊,怎麼說明能夠解決主題的呢?我的也是28版,但仍有中英文折行不合理的問題。This has been fixed in Emacs 28. You can now say (setq word-wrap-by-category t) to make Emacs respect kinsoku rules when wrapping lines visually.這個圖裡面沒 word 有英語單詞啊make Emacs respect kinsoku rules when wrapp,怎麼說明能夠解決主題的呢?我的也是28版,但仍有中英文折行不合理的問題。

什么都没开:

开了 (global-visual-line-mode 1)

开了 (global-visual-line-mode 1)(setq word-wrap-by-category t)

6 个赞

目前我遇到不符合自己使用习惯的是当一段没有空格的英文过长(如长链接),前面有空格时,会另起一行,或许需要针对链接再做处理。

开了 whitespace-modedisplay-line-numbers-mode 以便突出显示:

1 个赞

非常感谢!(。◕◡◕。)ノ

谢谢安利! 你不说我都不知道有这个功能.

用这个配置可以让更多字符折行,不仅仅是空格。

(setq dlukes/org-category-table (copy-category-table))
(dolist (char '(?- ?+ ?_ ?/ ?| ?\ ?. ?,))
  (modify-category-entry char ?| dlukes/org-category-table))

(add-hook! '(org-mode-hook markdown-mode-hook)
  (set-category-table dlukes/org-category-table)
  (setq-local word-wrap-by-category t)
  (visual-fill-column-mode))

dotfiles/emacs/doom/config.org at 11ecdaa4ea36c57071a864d4df73ba8900928375 · dlukes/dotfiles (github.com)

2 个赞