简体   繁体   English

使 LaTeX-insert-item 在 AucTeX 中下拉两行

[英]Make LaTeX-insert-item Drop Down Two Lines in AucTeX

I feel this is enough about Lisp to warrant here instead of TeX Stackexchange.我觉得这足以让 Lisp 在这里保证而不是 TeX Stackexchange。 Hopefully I am correct.希望我是正确的。 I want to use the command Cc Cj to insert two newlines, then an item.我想使用命令Cc Cj插入两个换行符,然后是一个项目。 When I call its definition, it tells me it is in latex.el .当我调用它的定义时,它告诉我它在latex.el The important snippet of code is重要的代码片段是

(unless (bolp) (LaTeX-newline))

I don't much know Lisp, but this seems like "unless the point is the beginning of the line, insert new line."我不太了解 Lisp,但这似乎是“除非点是行的开头,否则插入新行”。 Since I want two lines, I replaced it with由于我想要两行,我将其替换为

(unless (bolp) (LaTeX-newline)
        (LaTeX-newline))

But, the new code does not drop down two lines.但是,新代码不会下拉两行。 What did I do wrong?我做错了什么? Thanks.谢谢。 I've included the entire command definition in case my interpretation is wrong.我已经包含了整个命令定义,以防我的解释有误。

(defun LaTeX-insert-item ()
  "Insert a new item in an environment.
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)
            (LaTeX-newline))
    (if (assoc environment LaTeX-item-list)
    (funcall (cdr (assoc environment LaTeX-item-list)))
      (TeX-insert-macro "item"))
    (indent-according-to-mode)))

Your assumption about LaTeX-newline is right.您对LaTeX-newline假设是正确的。 It inserts a newline.它插入一个换行符。 Your modified function would work as you want it if it would be called.如果将调用您修改后的函数,它将按您的需要工作。

It most probably never gets called.它很可能永远不会被调用。

Maybe you added the definition to your init file but AUCTeX is loaded after that definition and LaTeX-insert-item becomes redefined in the original way.也许您将定义添加到 init 文件中,但 AUCTeX该定义之后加载,并且LaTeX-insert-item以原始方式重新定义。

You should not redefine LaTeX-insert-item but define a new function, eg my-LaTeX-insert-item and use that function as an :override advice for LaTeX-insert-item with the following line in your init file:您不应重新定义LaTeX-insert-item而是定义一个新函数,例如my-LaTeX-insert-item并将该函数用作LaTeX-insert-item:override建议,并在您的 init 文件中使用以下行:

(advice-add 'LaTeX-insert-item :override #'my-LaTeX-insert-item)

That advice works also if my-LaTeX-insert-item is defined before the package latex is loaded.如果在加载包latex之前定义了my-LaTeX-insert-item该建议也适用。

Note, that I assume that you use a more recent Emacs version with the package nadvice .请注意,我假设您使用更新的 Emacs 版本和包nadvice As far as I know nadvice was introduced in Emacs 24.4.据我所知, nadvice是在 Emacs 24.4 中引入的。

If Mx locate-library RET nadvice RET gives you the path of the library you are good to go.如果Mx locate-library RET nadvice RET为您提供了图书馆的路径,您就可以开始了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM