【问题标题】:emacs lisp: insert string removes the whitespaceemacs lisp:插入字符串删除空格
【发布时间】:2014-05-07 16:19:36
【问题描述】:

我想在当前缓冲区中插入一个字符串。我的函数在 emacs -q 下运行良好,但由于某种原因不适用于我的配置:“import”末尾的空格被忽略。插入的文本是importos,而不是import os

(defun my-python-import-add (to_import)
     (interactive "swhat to import ? ")
     (beginning-of-buffer)
     ;; save point
     ;; go to beginning of imports
     (newline)
     (insert "import " to_import)  ;; works with emacs -q
     ;; and call py-isort
     )

那么有没有更可靠的方法来插入字符串? (我想避免调试我的配置文件……)

我试过了

(insert (concat "import " to_import))

s.el

 (insert s-join " " '("import" to_import))

没有成功。 这太基础了……

谢谢!

ps:我知道rope-auto-import

【问题讨论】:

  • 如果插入带有空格的字符串,则带有空格的完整字符串将被插入缓冲区。你一定是做错了什么——也许你有一个旧的字节编译版本的文件?
  • 我有一个 pyc,删除它没有任何改变。也许是因为一种模式,比如“自动删除尾随空格”。调查起来并不容易。
  • Lyndydancer 指的是“.elc”文件:emacs 在存在时加载字节编译文件(如果它们是旧的,它会打印消息,但字节编译文件具有优先权)。如果你在初始化文件中重命名你的函数怎么办?重命名后重启emacs还能使用旧功能吗?
  • 哦,我明白了。我在ielm模式下编写了我的函数,所以我没有相关的.elc文件。

标签: emacs elisp


【解决方案1】:

对您的 cmets 更有信心,我进行了调查,发现一个所谓的非工作功能具有这种副作用。它试图将delete-trailing-whitespace 添加到before-save-hook

【讨论】:

    猜你喜欢
    • 2019-11-22
    • 1970-01-01
    • 1970-01-01
    • 2011-09-21
    • 1970-01-01
    • 1970-01-01
    • 2017-11-20
    相关资源
    最近更新 更多