auctex
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [AUCTeX] Hide a section/chapter with latex-fold-mode


From: Tassilo Horn
Subject: Re: [AUCTeX] Hide a section/chapter with latex-fold-mode
Date: Thu, 03 Jan 2013 14:44:00 +0100
User-agent: Gnus/5.130006 (Ma Gnus v0.6) Emacs/24.3.50 (gnu/linux)

celano <address@hidden> writes:

Hi Celano,

> Good morning and happy new year!

Thanks, I wish the same to you!

> I'd like to hide a section or a chapter in my file.tex, using
> tex-fold-mode
>
> I found environments and macros, but nothing about a hole chapter or
> section

No, `TeX-fold-mode' doesn't work for sectioning commands.  But for those
you can use `outline-minor-mode'.  AUCTeX already sets that up to work
with LaTeX documents.  Have a look at the emacs docs (info
"(emacs)Outline Mode").

For me, the standard outline-minor-mode keys (C-c @ ...) are too hard to
remember and inconvenient.  So I have some additional code that makes
TAB [or whatever key you like] on a outline heading (like \section{foo}
in a LaTeX doc) cycle through the states "collapsed", "shown with
children collapsed", and "everything shown".

--8<---------------cut here---------------start------------->8---
(defmacro define-context-key (keymap key dispatch)
  "Define KEY in KEYMAP to execute according to DISPATCH.

DISPATCH is a form that is evaluated and should return the
command to be executed.

If DISPATCH returns nil, then the command normally bound to KEY
will be executed.

Example:

  (define-context-key hs-minor-mode-map
     (kbd \"<C-tab>\")
     (cond
      ((not (hs-already-hidden-p))
       'hs-hide-block)
      ((hs-already-hidden-p)
       'hs-show-block)))

This will make <C-tab> show a hidden block.  If the block is
shown, then it'll be hidden."
  `(define-key ,keymap ,key
     `(menu-item "context-key" ignore
                 :filter ,(lambda (&optional ignored)
                            ,dispatch))))

(defun th-outline-context-p ()
  "Non-nil if `point' is on an outline-heading."
  (save-excursion
    (goto-char (line-beginning-position))
    (looking-at outline-regexp)))

(define-context-key outline-minor-mode-map
  (kbd "TAB")
  (when (th-outline-context-p)
    'org-cycle))
--8<---------------cut here---------------end--------------->8---

Bye,
Tassilo




reply via email to

[Prev in Thread] Current Thread [Next in Thread]