主要观点:作者以 Emacs 结合evil
(vim 模拟模式)写博客和代码,常有误按:w2<ret>
而想保存为2
文件的情况,为此在.emacs
中添加了一段代码(defun my:evil-write (&rest args) "I constantly hit :w2<ret> and save a file named 2. Verify that I want to do that" (if (equal "2" (nth 3 args)) (y-or-n-p "Did you really mean to save a file named 2?") t))(advice-add #'evil-write :before-while #'my:evil-write)
,:before-while
建议可在运行被建议函数前先运行该函数,若返回真值则按原函数运行,若返回nil
则不运行原函数,作者分享此代码供大家使用,且在 2024 年 4 月 16 日更新说明并非批评 Emacs 或evil
,而是借助 Emacs 的无限灵活性解决个人问题,希望自己的其他软件也能如此灵活。
关键信息:以 Emacs 和evil
写代码,常误按:w2<ret>
,添加代码解决,:before-while
建议及代码功能,2024 年 4 月 16 日更新说明。
重要细节:代码(defun my:evil-write (&rest args)...)
中通过判断第三个参数是否为"2"
来决定是否提示确认保存为2
文件,(advice-add #'evil-write :before-while #'my:evil-write)
将该函数添加为evil-write
的建议函数。
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。