Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

When working with some environments (function and friends from l3doc prompted this), it is desirable to have the environment's arguments visible at all times:

Some text that, in reality, shouldn't be here in an l3doc
\begin{function}{\tl_new:N}
  Some documentation...
\end{function}
more inappropriate text

When folding this using C-c C-o C-e, everything goes away (which is useful for environments like minipage, etc.):

Some text that, in reality, shouldn't be here in an l3doc
  [function]
more inappropriate text

Is there any way to turn this into the following for certain environments?

Some text that, in reality, shouldn't be here in an l3doc
  [function]{\tl_new:N}
more inappropriate text

(If only a solution for all environments exists easily, I can manage with turning on/off the mode.)


If the solution would be similar, it would be really cool if you could have some sort of marker, say %!!, that would always stay visible in folded environments.

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

Start of a solution, based on this answer

(defun mg-TeX-fold-environment-with-argument ()
  "Hide the current environment with \"[environment]{argument}\"."
  (interactive)
  (if (equal (LaTeX-current-environment) "function")
      (let ((env-end (save-excursion
               (LaTeX-find-matching-end)
               (point)))
        env-start priority ov)
    (setq env-start (save-excursion
              (LaTeX-find-matching-begin)
              (looking-at "\\\\begin{function}\\({[^}]*}\\)")
              (point)))
    (if (and env-start env-end)
        (progn
          (setq priority (TeX-overlay-prioritize env-start env-end))
          (setq ov (make-overlay env-start env-end
                     (current-buffer) t nil))
          (overlay-put ov 'category 'TeX-fold)
          (overlay-put ov 'priority priority)
          (overlay-put ov 'evaporate t)
          (overlay-put ov 'TeX-fold-display-string-spec
               (concat "[function]" (match-string-no-properties 1)))
          (TeX-fold-hide-item ov))
      (message "No environment found")))))
share|improve this answer
    
This is really cool! Would you mind if I took a crack at generalizing it and posting this to GitHub? –  Sean Allred Aug 14 '13 at 14:58
1  
No, as long as you attribute it (though I shamelessly stole the code from the TeX-fold-make-overlay function), this site is under CC-BY-SA after all ;-) –  giordano Aug 14 '13 at 16:10
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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