简体   繁体   中英

Make LaTeX-insert-item Drop Down Two Lines in AucTeX

I feel this is enough about Lisp to warrant here instead of TeX Stackexchange. Hopefully I am correct. I want to use the command Cc Cj to insert two newlines, then an item. When I call its definition, it tells me it is in 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." 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. 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.

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:

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

Note, that I assume that you use a more recent Emacs version with the package nadvice . As far as I know nadvice was introduced in Emacs 24.4.

If Mx locate-library RET nadvice RET gives you the path of the library you are good to go.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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