让 CM-RET 插入 \item[]

发布于 2024-12-11 04:09:31 字数 372 浏览 0 评论 0原文

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

我想要的是 CM-RET

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

In AUCTeX M-RET is bound to (LaTeX-insert-item) which makes a new properly indented line and inserts \item and a space after which the cursor is placed. I would like to extend this feature so that C-M-RET has similar functionality but for \item[description].

What I would like is for C-M-RET to

  1. make a new properly indented line and insert \item[],
  2. place the cursor between the square brackets, and
  3. place the cursor one space after \item[] as Tab is pressed.

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

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

发布评论

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

评论(2

流绪微梦 2024-12-18 04:09:31

以下函数抄袭自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)))

如果您想要 MC-RET,请使用 (元控制返回),尽管它似乎仅适用于 Alt 键,而不是 Esc 键(通常表现相同...)

The following function is cribbed from latex.el, and modified slightly to call the argument-prompting version LaTeX-item-argument instead of just inserting the item directly.

(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)))

You can bind that function to any key you like:

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

If you want M-C-RET, use (meta control return) instead, though it only seems to work with the Alt key, and not the Esc key (which usually behaves the same...)

影子是时光的心 2024-12-18 04:09:31

听起来您想要 Textmate 片段行为。

您需要 yasnippet 来执行代码段扩展/字段移动。 IMO,将其绑定到键并不是一个好的解决方案,因为键的数量是有限的,但 yasnippet 确实允许您这样做。

It sounds like you want Textmate snippets behavior.

You need yasnippet to do the snippet expansion/field movement. IMO, it's not a good solution to bind this to a key because the number of keys is limited, but yasnippet does allow you to do that as well.

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