1

When using the adaptive-wrap mode in the plain latex-mode (no AUCTeX), I want to give extra indents to only lines beginning with "\item". For example, I currently have:

\begin{itemize}
\item This is a very very very very very very very (soft-wrap here)
very very very very very very long line.

  And this is another very very very very very very (soft-wrap here)
  very long line.
\end{itemize}

Note that there are two leading white-spaces at the beginning of the second paragraph (" And this is ..."), which wraps by adaptive-wrap nicely to my eyes. Now I would also like the paragraph beginning with "\item This is ..." to wrap with extra indentation even though it has no leading white-spaces. That is, I would like it displayed as follows:

\begin{itemize}
\item This is a very very very very very very very (soft-wrap here)
  very very very very very very long line.

  And this is another very very very very very very (soft-wrap here)
  very long line.
\end{itemize}

Please note the indentation at the beginning of the line next to the first soft-wrap. Could I do it somehow? Any help would be appreciated.

Globally setting adaptive-wrap-extra-indent to 2 makes all lines have 2 extra indents, which I want to avoid. I would like only the line beginning with "\item" have the effect.

Thank you.

PS. I am already very happy with the combination of latex-mode and adaptive-wrap, and this is the final issue I would like to resolve. I have the following in my .emacs file with some other stuff.

(load-library "adaptive-wrap")
(visual-line-mode 1)
(adaptive-wrap-prefix-mode 1)
(whitespace-newline-mode 1)
0

I found a solution. I added the following in .emacs, after (load-library "adaptive-wrap"):

(load-library "adaptive-wrap")

;;; added from here
(defun begin-with-item-p ()
  "Determine whether the beginning of line is \\item"
  (let ((curpos (point)))
    (beginning-of-line)
    (setq ret (looking-at "[    ]*\\\\item[^A-Za-z]"))
    ;; Above, [    ] is SPC followed by TAB (ctrl-q TAB)
    (goto-char curpos) ret))

;; HACK https://elpa.gnu.org/packages/adaptive-wrap-0.5.1.el
(defun adaptive-wrap-prefix-function (beg end)
  "Indent the region between BEG and END with adaptive filling."
  (goto-char beg)
  (while (< (point) end)
    (let ((lbp (line-beginning-position)))
      ;; ---- BEGIN ------------------------------------------------
      (setq adaptive-wrap-extra-indent (if (begin-with-item-p) 2 0))
      ;; ---- END --------------------------------------------------
      (put-text-property (point)
                         (progn (search-forward "\n" end 'move) (point))
                         'wrap-prefix
                         (adaptive-wrap-fill-context-prefix lbp (point))))))
;;; added to here

This piece of codes replace adaptive-wrap-prefix-function. The amount of indentation is hard-coded (2 and 0), but I can always edit the part if I want.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.