我正在从 Google Chrome 或 PDF 复制文本,然后粘贴到 Emacs 中。
原文中有智能引号。我不希望输出中有智能引号。
有没有办法,无论是在复制方面还是在粘贴方面,自动删除智能引号?
答案1
怎么样:
(defun replace-smart-quotes (beg end)
"Replace 'smart quotes' in buffer or region with ascii quotes."
(interactive "r")
(format-replace-strings '(("\x201C" . "\"")
("\x201D" . "\"")
("\x2018" . "'")
("\x2019" . "'"))
nil beg end))
将其放入您的程序中~/.emacs
,您应该能够使用它M-x replace-smart-quotes来修复当前缓冲区或选定区域中的所有引号。
为了避免重新启动 Emacs 以使更改生效,请将光标移至with~/.emacs
的末尾并对其进行评估。defun
M-C-eC-x C-e
更新回复评论:
要在拖动(粘贴)时自动执行此操作,您可以执行以下操作:
(defun yank-and-replace-smart-quotes ()
"Yank (paste) and replace smart quotes from the source with ascii quotes."
(interactive)
(yank)
(replace-smart-quotes (mark) (point)))
如果您希望在点击时执行此操作C-y,则可以使用以下命令进行绑定:
(global-set-key (kbd "C-y") 'yank-and-replace-smart-quotes)
然而,使用另一个键可能是一个更好的主意(也许C-c y),因为这将使用一些默认yank
功能。
答案2
从:https://readingworldmagazine.com/emacs/2020-02-20-emacs-enter-exit-appearance/
(defun replace-garbage-chars ()
"Replace non-rendering MS and other garbage characters with latin1 equivalents."
(interactive)
(save-excursion ;save the current point
(replace-string "\221" "`" nil (point-min) (point-max))
(replace-string "\222" "'" nil (point-min) (point-max))
(replace-string "\226" "-" nil (point-min) (point-max))
(replace-string "\227" "--" nil (point-min) (point-max))
(replace-string "\223" "(" nil (point-min) (point-max))
(replace-string "\224" ")" nil (point-min) (point-max))
(replace-string "\205" "..." nil (point-min) (point-max))
(replace-string "\225" "-" nil (point-min) (point-max))
(replace-string "\344" "" nil (point-min) (point-max))
(replace-string "\374" "" nil (point-min) (point-max))
(replace-string "\337" "" nil (point-min) (point-max))
(replace-string "\366" "" nil (point-min) (point-max))
(replace-string "\247" "***" nil (point-min) (point-max))
(replace-string "\267" "****" nil (point-min) (point-max))
(replace-string "\351" " " nil (point-min) (point-max))
(replace-string "\347" " " nil (point-min) (point-max))
(replace-string "\352" " " nil (point-min) (point-max))
(replace-string "\342" " " nil (point-min) (point-max))
(replace-string "\307" " " nil (point-min) (point-max))
(replace-string "\340" " " nil (point-min) (point-max))
(replace-string "\340" " " nil (point-min) (point-max))
(replace-string "\364" " " nil (point-min) (point-max))
(replace-string "\353" " " nil (point-min) (point-max))
(replace-string "\243" " " nil (point-min) (point-max))
));end replace-garbage-characters
;bind-key replace-garbage-characters
(bind-key "\C-cr" 'replace-garbage-chars)