branch: main commit a853f3fed7ef3648ecd9a31e0f5102cb5401a95d Author: Ikumi Keita <ik...@ikumi.que.jp> Commit: Ikumi Keita <ik...@ikumi.que.jp>
Improve insertion of \item (bug#74056) * latex.el (LaTeX-insert-item): On whitespace-only line, use that line to put \item and don't create a new line after it. * tests/latex/latex-test.el (LaTeX-insert-item-in-whitespace-only-line): New test. --- latex.el | 13 ++++++++++++- tests/latex/latex-test.el | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/latex.el b/latex.el index 5e1c628c..91aa16b5 100644 --- a/latex.el +++ b/latex.el @@ -1535,7 +1535,18 @@ You may use `LaTeX-item-list' to change the routines used to insert the item." (when (and (TeX-active-mark) (> (point) (mark))) (exchange-point-and-mark)) - (unless (bolp) (LaTeX-newline)) + (if (save-excursion + ;; If the current line has only whitespace characters, put + ;; the new \item on this line, not creating a new line + ;; below. + (goto-char (line-beginning-position)) + (if LaTeX-insert-into-comments + (re-search-forward + (concat "\\=" TeX-comment-start-regexp "+") + (line-end-position) t)) + (looking-at "[ \t]*$")) + (delete-region (match-beginning 0) (match-end 0)) + (LaTeX-newline)) (if (assoc environment LaTeX-item-list) (funcall (cdr (assoc environment LaTeX-item-list))) (TeX-insert-macro "item")) diff --git a/tests/latex/latex-test.el b/tests/latex/latex-test.el index e22d2a08..d7d202fc 100644 --- a/tests/latex/latex-test.el +++ b/tests/latex/latex-test.el @@ -730,4 +730,22 @@ check the indentation for optional argument of \\usepackage." (insert-file-contents docTeX/out) (buffer-string))))) +;; bug#74056 +(ert-deftest LaTeX-insert-item-in-whitespace-only-line () + "Test if `LaTeX-insert-item' doesn't insert spurious line." + (with-temp-buffer + (LaTeX-mode) + (insert "\ +\\begin{itemize} +\\item abc +\s\s\t") + (backward-char 1) + (LaTeX-insert-item) + (should (string= + (buffer-string) + "\ +\\begin{itemize} +\\item abc +\\item ")))) + ;;; latex-test.el ends here