Emacs 命令在光标上方插入和缩进行

标签 emacs elisp

当我意识到我需要(编辑)上一行的变量定义(或类似的东西)时,我经常发现自己在一行上打字。我想要的是

  • 从一行上的任何地方按 C-return 并将光标移动到上面新插入的空白行,缩进正确(或至少与原始行相同)。
  • 能够拉取任何文本...
  • 和 C-u C-space 回到原来的位置

  • 我已经设法做到了#1,但是我的 emacs-fu 不够强大,无法完成其余的工作。

    最佳答案

    这是我简陋的解决方案:

    (defun my-insert-before-line ()
      (interactive)
      (save-excursion
        (beginning-of-line)
        ; I've changed the order of (yank) and (indent-according-to-mode)
        ; in order to handle the case when yanked line comes with its own indent
        (yank)(indent-according-to-mode)
        ; could be as well changed to simple (newline) it's metter of taste
        ; and of usage
        (newline-and-indent)))
    

    希望它有帮助。

    关于Emacs 命令在光标上方插入和缩进行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/622440/

    相关文章:

    emacs - 在 Emacs 中如何仅在代码区域中操作(即搜索)?

    Emacs gud 提升前缀键错误

    elisp - 从 Emacs 缓冲区中提取 URL?

    emacs - 如何使用 emacs/elisp 获取当前缓冲区信息的开始/结束?

    emacs - wdired模式 : create, 复制、删除文件和目录

    emacs - Emacs 命令的打开定义

    vim - 如何为 Groovy 类生成 TAGS 文件以便在 VIM/Emacs 中使用

    emacs - 如何对 .emacs.d 目录中的所有内容进行字节编译?

    variables - 如何访问列表中变量的值?

    emacs - 自定义emacs-prelude提供的软件包列表