【问题标题】:Make C-M-RET insert \item[]使 C-M-RET 插入 \item[]
【发布时间】:2011-10-19 09:39:55
【问题描述】:

在 AUCTeX 中,M-RET 绑定到 (LaTeX-insert-item),这会创建一个新的正确缩进的行并插入 \item 和一个空格,然后将光标放置在该空格之后。我想扩展此功能,以便 C-M-RET 具有类似的功能,但适用于\item[description]

我想要的是 C-M-RET

  1. 新建一个适当缩进的行并插入\item[]
  2. 将光标放在方括号之间,然后
  3. 在按下 Tab 时,将光标放在 \item[] 后一格。

【问题讨论】:

  • Auctex 知道您何时处于描述环境中,并自动修改M-RET 的行为。这对您不起作用,还是您在其他情况下使用 \item[description]?

标签: emacs keyboard-shortcuts auctex


【解决方案1】:

下面的函数是从latex.el 中抄来的,并稍作修改以调用参数提示版本LaTeX-item-argument 而不是直接插入项目。

(defun LaTeX-insert-item-arg ()
  "Insert a new item in an environment, prompting for an item label.
You may use `LaTeX-item-list' to change the routines used to insert the item."
  (interactive "*")
  (let ((environment (LaTeX-current-environment)))
    (when (and (TeX-active-mark)
           (> (point) (mark)))
      (exchange-point-and-mark))
    (unless (bolp) (LaTeX-newline))
    (if (assoc environment LaTeX-item-list)
    (funcall (cdr (assoc environment LaTeX-item-list)))
      (LaTeX-item-argument)) ;; ONLY THIS LINE IS DIFFERENT
    (indent-according-to-mode)))

您可以将该功能绑定到您喜欢的任何键:

(add-hook 'LaTeX-mode-hook (lambda () 
    (local-set-key [(control return)] 'LaTeX-insert-item-arg)))

如果您想要M-C-RET,请改用(meta control return),尽管它似乎只适用于Alt 键,而不是Esc 键(通常行为相同...)

【讨论】:

    【解决方案2】:

    听起来你想要 Textmate sn-ps 行为。

    您需要yasnippet 来执行 sn-p 扩展/字段移动。 IMO,将它绑定到密钥不是一个好的解决方案,因为密钥的数量是有限的,但 yasn-p 也允许您这样做。

    【讨论】:

    • (LaTeX-insert-item) 知道 LaTeX 环境,因此它可以正确缩进。这就是为什么我想要类似的功能,但对于\item[]。我不知道如何让 yasn-p 了解 LaTeX 环境。此外,C-M-RETC-RET 未绑定在 AUCTeX 中。
    • 我不使用 LaTeX,但 yasn-p 能够在缩进定义明确的主要模式下缩进 sn-ps,即 TAB 缩进正确。如果您想要流畅的字段填充体验,我会以 yasn-p 为起点。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-03-31
    • 1970-01-01
    • 1970-01-01
    • 2023-04-08
    • 2020-08-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多