如何删除emacs中的非ascii字符

use*_*456 2 unicode emacs character

我对 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."))))
Run Code Online (Sandbox Code Playgroud)

use*_*456 5

我想我通过修改这篇文章的答案找到了答案:如何折叠区域中的空格?

这是我想出的:

(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 "")))))
Run Code Online (Sandbox Code Playgroud)