Emacs 应将单词的第二个字符设置为小写

发布于 2024-09-13 11:38:38 字数 147 浏览 3 评论 0原文

在大多数情况下,我正在写德语文本。大多数单词以大写字母开头,后跟小写字母。有时我打字太快,而且单词的第二个字母也大写。为了解决这个问题,我问自己是否可以编写一个自动更改第二个字母大小写的函数。可选,仅当第三个及以下字母为小写时才会发生这种情况。您知道这是否可行吗?您有什么建议吗?

In most cases I'm writing german texts. Most words start with an uppercase letter followed by lower case letters. Sometimes I'm typing too fast and also the second letter of a word is typed upper case. To work around this issue I asked myself if it is poosible to write a function which automatically changes the case of the second letter. Optional this should only happen if the third and following are in lower case. Do you know if this is possible and do you have any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

挥剑断情 2024-09-20 11:38:38

这是一个“永远在线”的版本,可以在您键入时进行修复。它会让您输入所有大写单词,但一旦检测到大小写混合,它就会大写。

(defun blah (s e l)
  (let ((letter (string-to-char (word-before-point))))
    (if (and (eq letter (upcase letter))
             (not (eq (char-before) (upcase (char-before)))))
        (capitalize-word -1))))
(add-to-list 'after-change-functions 'blah)

Here's an 'always on' version that fixes as you type. It will let you type all uppercase words, but as soon as it detects mixed case it will capitalize.

(defun blah (s e l)
  (let ((letter (string-to-char (word-before-point))))
    (if (and (eq letter (upcase letter))
             (not (eq (char-before) (upcase (char-before)))))
        (capitalize-word -1))))
(add-to-list 'after-change-functions 'blah)
电影里的梦 2024-09-20 11:38:38

如果单词中的第一个字母为大写且所有其他字母均为小写,则以下命令将把每个单词的第二个字母转换为小写:

(defun fix-double-uppercase-at-start-of-words ()
  (interactive)
  (let ((case-fold-search nil))
    (save-match-data
      (while (re-search-forward "\\b\\([[:upper:]]\\)\\([[:upper:]]\\)\\([[:lower:]]*\\)\\b" nil t)
        (replace-match (concat (match-string 1)
                               (downcase (match-string 2))
                               (match-string 3))
                       t)))))

该命令将作用于从当前光标位置到单词末尾(可见)的所有单词。缓冲。

Here's a command that will convert to lowercase the second letter of each word if the first letter is uppercase and all other letters in the word are lowercase:

(defun fix-double-uppercase-at-start-of-words ()
  (interactive)
  (let ((case-fold-search nil))
    (save-match-data
      (while (re-search-forward "\\b\\([[:upper:]]\\)\\([[:upper:]]\\)\\([[:lower:]]*\\)\\b" nil t)
        (replace-match (concat (match-string 1)
                               (downcase (match-string 2))
                               (match-string 3))
                       t)))))

The command will work on all words from the current cursor position to the (visible) end of the buffer.

仙气飘飘 2024-09-20 11:38:38

您可以设置一个次要模式,将所有大写字符映射到特殊输入功能。

请参阅:

http://gist.github.com/516242

You could setup a minor mode mapping all upcase characters to special input function.

See:

http://gist.github.com/516242

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文