gpt4 book ai didi

unicode - 如何删除 emacs 中的非 ascii 字符

转载 作者:行者123 更新时间:2023-12-02 17:16:09 24 4
gpt4 key购买 nike

我是 elisp 编程的新手,我正在尝试编写一个 Emacs elisp 函数来删除突出显示区域中的所有非 ASCII 字符。我在这里找到了一个关于如何查找非 ASCII 字符的示例 elisp 函数:https://www.emacswiki.org/emacs/FindingNonAsciiCharacters .我试图自己修改它,但无法让它工作。有人可以告诉我如何修改以下 elisp 函数以删除 GNU Emacs 中突出显示区域中的所有非 ASCII 字符:

(defun find-first-non-ascii-char ()
"Find the first non-ascii character from point onwards."
(interactive)
(let (point)
(save-excursion
(setq point
(catch 'non-ascii
(while (not (eobp))
(or (eq (char-charset (following-char))
'ascii)
(throw 'non-ascii (point)))
(forward-char 1)))))
(if point
(goto-char point)
(message "No non-ascii characters."))))

最佳答案

我想我通过修改这篇文章的答案找到了答案:how to collapse whitespaces in a region?

这是我想出的:

(defun del-binary_characters (beg end)
"Delete binary characters in a region"
(interactive "r")
(save-excursion
(save-restriction
(narrow-to-region beg end)
(goto-char (point-min))
(while (re-search-forward "[^[:ascii:]]" nil t)
(replace-match "")))))

关于unicode - 如何删除 emacs 中的非 ascii 字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46265832/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com