When I run the command LaTeX-environment (bound to C-c C-e by default) Helm properly selects from a list of all relevant environments (i.e. the same list I'd get without Helm turned on). The prompt reads "Environment type: (default foo)" where 'foo' is the value stored in LaTeX-default-environment (which is in turn set to whatever I ended up using in the last call to LaTeX-environment). If I hit return now, however, I get an 'abstract' environment, the first entry in the Helm buffer.

How can I get Helm to respect LaTeX-default-environment?


You cannot. According to helm's author it is AUCTEX' fault for not using completing-read correctly which makes helm-mode return the candidate verbatim. A possible workaround is described in the linked thread which is either making AUCTEX' authors fix the bug for every instance of completing-read or patching it yourself.

To do the latter, the following should work (untested, most code taken from AUCTEX):

(eval-after-load 'latex
  '(defun LaTeX-environment (arg)
      (interactive "*P")
      (let ((environment (completing-read (concat "Environment type: (default "
                                                  (if (TeX-near-bobp)
                                                  ") ")
                                          (LaTeX-environment-list) nil t nil
                                          'LaTeX-environment-history LaTeX-default-environment)))
        ;; Get default
        (cond ((and (zerop (length environment))
               (setq environment "document"))
              ((zerop (length environment))
               (setq environment LaTeX-default-environment))
               (setq LaTeX-default-environment environment)))

        (let ((entry (assoc environment (LaTeX-environment-list))))
          (if (null entry)
              (LaTeX-add-environments (list environment)))

          (if arg
              (LaTeX-modify-environment environment)
            (LaTeX-environment-menu environment))))))
  • 5
    Already fixed upstream.
    – giordano
    Oct 28 '14 at 23:31
  • Thanks, guess the questioner has to update his AUCTEX installation then and check whether this fixes it. If not, the snippet above should still apply.
    – wasamasa
    Oct 29 '14 at 0:16

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.