[英]Change the format of a word in Emacs-AUCTeX without actually selecting it
One nice feature of modern word processors is that one can change the format (say, from roman to italic) of a word without actually selecting it; 现代文字处理器的一个很好的特点是,可以改变单词的格式(例如,从罗马到斜体)而不实际选择它; one just needs to place the text cursor within the word and tell the word processor (via a keyboard shortcut) to change its format. 只需要将文本光标放在单词中并告诉文字处理器(通过键盘快捷键)更改其格式。 (Smart editing, I believe it is sometimes called.) (智能编辑,我相信它有时被称为。)
Is there a way of doing that in Emacs-AUCTeX? 有没有办法在Emacs-AUCTeX中这样做? (The usual way to change the format---that is, insert a format command---is to select the word [mark its region] and then press the key combination for the command [eg Cc Cf Ci
to insert \\textit{}
].) (更改格式的常用方法 - 即插入格式命令---是选择单词[标记其区域],然后按下命令的组合键[例如Cc Cf Ci
to insert \\textit{}
]。)
In case there is no solution right from the spot, Emacs offers two ways basically once the succession of commands/keys is known: 如果现场没有解决方案,Emacs基本上提供了两种方法,一旦知道了一系列命令/键:
either store them into a keyboard-macro, which be might called with just one key - or put all the commands into a function, make it a command, assign a key. 要么将它们存储到键盘宏中,只需要用一个键调用它 - 或者将所有命令放入一个函数中,使其成为一个命令,分配一个键。
The shortcut Cc Cf calls TeX-font
. 快捷方式Cc Cf调用TeX-font
。 Then it emphasizes/italicizes/whatever, based on the last key chord. 然后它根据最后的键和弦强调/斜体/任意。 So the solution is to advice this function: 所以解决方案是建议这个功能:
(defvar TeX-font-current-word t)
(defadvice TeX-font (before TeX-font-word (replace what))
"If nothing is selected and `TeX-font-current-word' is not nil,
mark current word before calling `TeX-font'."
(when (and TeX-font-current-word
(not replace)
(not (region-active-p))
(not (looking-at "\\s-")))
(unless (looking-back "\\s-") (backward-word))
(mark-word)))
(ad-activate 'TeX-font)
Now, when no region is selected, TeX-font
will work as if the current word was selected. 现在,当没有选择区域时, TeX-font
将像选择当前单词一样工作。 You can turn this behavior on/off by setting TeX-font-current-word
to t
/ nil
. 您可以通过将TeX-font-current-word
为t
/ nil
来打开/关闭此行为。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.