Skip to content

Commit

Permalink
Use the digits to hide and show sections.
Browse files Browse the repository at this point in the history
* magit.el (magit-section-lineage, magit-section-show-level, magit-show-level,
magit-define-level-shower-1): New.
(magit-mode-map): Bind the digits and M-digits to magit-show-level-N
and magit-show-level-N-all.
* magit.texi: Document it in a new chapter for Sections.
  • Loading branch information
mvollmer committed Feb 7, 2009
1 parent 64d24aa commit 59bd8ec
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 15 deletions.
5 changes: 5 additions & 0 deletions NEWS
Expand Up @@ -17,6 +17,11 @@ Changes in magit 0.7:
* M-x magit-status doesn't prompt anymore for a directory when invoked
from within a Git repository. Use C-u to force a prompt.

* The digit keys '1', '2', '3', and '4' now show sections on the
respective level and hide everything below. With Meta, they work on
all sections, without, they work only on sections that are a parent
or child of the current section.

* Magit works better with oldish Gits that don't understand "--graph"
for example.

Expand Down
49 changes: 45 additions & 4 deletions magit.el
Expand Up @@ -680,10 +680,42 @@ Many Magit faces inherit from this one by default."
(t
(magit-section-expand s))))))

(defun magit-section-lineage (s)
(and s (cons s (magit-section-lineage (magit-section-parent s)))))

(defun magit-section-show-level (section level threshold path)
(magit-section-set-hidden section (>= level threshold))
(when (< level threshold)
(if path
(magit-section-show-level (car path) (1+ level) threshold (cdr path))
(dolist (c (magit-section-children section))
(magit-section-show-level c (1+ level) threshold nil)))))

(defun magit-show-level (level all)
(if all
(magit-section-show-level magit-top-section 0 level nil)
(let ((path (reverse (magit-section-lineage (magit-current-section)))))
(magit-section-show-level (car path) 0 level (cdr path)))))

(defmacro magit-define-level-shower-1 (level all)
(let ((fun (intern (format "magit-show-level-%s%s"
level (if all "-all" ""))))
(doc (format "Show sections on level %s." level)))
`(defun ,fun ()
,doc
(interactive)
(magit-show-level ,level ,all))))

(defmacro magit-define-level-shower (level)
`(progn
(magit-define-level-shower-1 ,level nil)
(magit-define-level-shower-1 ,level t)))

(defmacro magit-define-section-jumper (sym title)
(let ((fun (intern (format "magit-jump-to-%s" sym)))
(doc (format "Jump to section `%s'." title)))
`(defun ,fun ()
,doc
(interactive)
(magit-goto-section '(,sym)))))

Expand Down Expand Up @@ -891,17 +923,26 @@ Many Magit faces inherit from this one by default."
(magit-define-section-jumper staged "Staged changes")
(magit-define-section-jumper unpushed "Unpushed commits")

(magit-define-level-shower 1)
(magit-define-level-shower 2)
(magit-define-level-shower 3)
(magit-define-level-shower 4)

(defvar magit-mode-map
(let ((map (make-keymap)))
(suppress-keymap map t)
(define-key map (kbd "n") 'magit-goto-next-section)
(define-key map (kbd "p") 'magit-goto-previous-section)
(define-key map (kbd "TAB") 'magit-toggle-section)
(define-key map (kbd "<backtab>") 'magit-expand-collapse-section)
(define-key map (kbd "1") 'magit-jump-to-untracked)
(define-key map (kbd "2") 'magit-jump-to-unstaged)
(define-key map (kbd "3") 'magit-jump-to-staged)
(define-key map (kbd "4") 'magit-jump-to-unpushed)
(define-key map (kbd "1") 'magit-show-level-1)
(define-key map (kbd "2") 'magit-show-level-2)
(define-key map (kbd "3") 'magit-show-level-3)
(define-key map (kbd "4") 'magit-show-level-4)
(define-key map (kbd "M-1") 'magit-show-level-1-all)
(define-key map (kbd "M-2") 'magit-show-level-2-all)
(define-key map (kbd "M-3") 'magit-show-level-3-all)
(define-key map (kbd "M-4") 'magit-show-level-4-all)
(define-key map (kbd "g") 'magit-refresh)
(define-key map (kbd "G") 'magit-refresh-all)
(define-key map (kbd "s") 'magit-stage-item)
Expand Down
52 changes: 41 additions & 11 deletions magit.texi
Expand Up @@ -30,6 +30,7 @@ as an extension to Emacs.
@menu
* Introduction::
* Acknowledgments::
* Sections::
* Status::
* Untracked files::
* Staging and Committing::
Expand Down Expand Up @@ -93,6 +94,44 @@ Alex Ott contributed support for git svn. Thanks!
Marcin Bachry contributed bug fixes and support for decorated logs.
Thanks!

@node Sections
@chapter Sections

All Magit buffers are structured into nested 'sections'. These
sections can be hidden and shown individually. When a section is
hidden, only its first line is shown and all its children are
completely invisible.

The most fine-grained way to control the visibility of sections is the
@kbd{TAB} key. It will to toggle the current section (the section
that contains point) between being hidden and being shown.

Typing @kbd{S-TAB} toggles the visibility of the children of the
current section. When all of them are shown, they will all be hidden.
Otherwise, when some or all are hidden, they will all be shown.

The digit keys @kbd{1}, @kbd{2}, @kbd{3}, and @kbd{4} control the
visibility of sections based on levels. Hitting @kbd{2}, for example,
will show sections on levels one and two, and will hide sections on
level 3. However, only sections that are a parent or child of the
current section are affected.

For example, when the current section is on level 3 and you hit
@kbd{1}, the grand-parent of the current section (which is on level
one) will be show, the parent of the current section (level 2) will be
hidden. The visibility of no other section will be changed.

This sounds a bit complicated, but you'll figure it out.

Using @kbd{M-1}, @kbd{M-2}, @kbd{M-3}, and @kbd{M-4} is similar to the
unmodified digits, but now all sections on the respective level are
affected, regardless of whether they are related to the current
section.

For example, @kbd{M-1} will only show the first lines of the top-level
sections and will hide everything else. Typing @kbd{M-4} on the other
hand will show everything in the status buffer.

@node Status
@chapter Status

Expand All @@ -114,17 +153,8 @@ the status buffer in this way after saving a file in Emacs.
The header at the top of the status buffer shows a short summary of
the repository state: where it is located, which branch is checked
out, etc. Below the header are a number of sections that show details
about the working tree and the staging area. Only sections that are
not empty are shown.

You control how much of a section is visible by moving point to its
title and hitting @kbd{TAB} or @kbd{S-TAB}. Hitting @kbd{TAB} will
toggle between hiding and showing the section. A hidden section only
shows its first line. You can also control the visibility of
sub-sections in this way. Hitting @kbd{S-TAB} will fully expand a
section by showing it and all of its sub-sections. If a section is
already fully expanded, @kbd{S-TAB} will collapse it: the section
itself remains shown, but all its immediate sub-sections are hidden.
about the working tree and the staging area. You can hide and show
them as described in the previous section.

The first section shows @emph{Untracked files}, if there are any. See
@ref{Untracked files} for more details.
Expand Down

0 comments on commit 59bd8ec

Please sign in to comment.