Update some changed export keybindings
[worg.git] / org-tutorials / org-outside-org.org
blobe4b2c6adab22b4ce3f259ba71f0463aad2dbd4d5
1 #+TITLE:      Org-mode outside Org-mode
2 #+AUTHOR:     Thorsten Jolitz, François Pinard
3 #+EMAIL:      tjolitz at gmail dot com
4 #+DATE:        <2013-03-12 Di>
5 #+OPTIONS:    H:4 num:nil toc:4 \n:nil @:t ::t |:t ^:t -:t f:t *:t TeX:t LaTeX:t skip:nil d:(HIDE) tags:not-in-toc
6 #+STARTUP:    align fold nodlcheck oddeven lognotestate
7 #+SEQ_TODO:   TODO(t) INPROGRESS(i) WAITING(w@) | DONE(d) CANCELED(c@)
8 #+TAGS:       Write(w) Update(u) Fix(f) Check(c)
9 #+LANGUAGE:   en
10 #+PRIORITIES: A C B
11 #+CATEGORY:   worg
13 # This file is released by its authors and contributors under the GNU
14 # Free Documentation license v1.3 or later, code examples are released
15 # under the GNU General Public License v3 or later.
17 [[file:index.org][{Back to Worg's index}]]
19 * Introduction
20   :PROPERTIES:
21   :CUSTOM_ID: introduction
22   :END:
24   Once one gets used to Org-mode, it's hard to live without it. Even its most
25   basic feature, the hierarchical tree-like structuring of files, can be
26   missed badly when editing files in other GNU Emacs major-modes, not to
27   mention the convenient navigation, structure-editing and visibility-cycling
28   functionality Org-mode offers for these tree-like structures.
30   One especially important case where Org-mode users might miss Org-mode
31   functionality is their =.emacs= configuration file. These Emacs Lisp files
32   might become huge, for example [[http://www.mygooglest.com/fni/dot-emacs.html][Fabrice Niessen's .emacs]] has some 9720 lines,
33   and structuring them only using Emacs Lisp comments (=;=) easily becomes a
34   creative nightmare (many approaches for structuring a .emacs file can be
35   found on [[http://www.dotemacs.de/index.html][the very unofficial dotemacs home]] page). 
37   Another typical case where Org-mode's editing facilities are missing is
38   writing the comment-header sections of Emacs Lisp source code files. These
39   sections often contain extensive explanations of the development-history,
40   installation-process and usage of the library, but are just that - Emacs
41   Lisp comment-sections. Sometimes even the comment-strings of important and
42   complex Emacs Lisp functions contain long and complicated text parts that
43   are not easy to edit as comments. 
45   Last not least, anybody who has used =C-c C-j (org-goto)= for looking up a
46   different location in the current org-file, keeping current visibility,
47   might have wondered if a kind of 'remote-buffer-control' via an associated
48   read-only buffer might not be a generally useful idea.
50 * Org-mode everywhere
51   :PROPERTIES:
52   :CUSTOM_ID: org-mode-everywhere
53   :END:
54 ** File Structuring
55    :PROPERTIES:
56    :CUSTOM_ID: file-structuring
57    :END:
58 *** Orgstruct 
59     :PROPERTIES:
60     :CUSTOM_ID: orgstruct-minor-mode
61     :END:
63    One possibility to enjoy Org-mode's structure-editing and list-formatting
64    facilities outside Org-mode buffers is /Orgstruct minor mode/. Let's cite
65    from the [[https://orgmode.org/manual/Orgstruct-mode.html][Org-mode manual]]:
67 #+begin_example
68     If you like the intuitive way the Org mode structure editing and list
69     formatting works, you might want to use these commands in other modes like
70     Text mode or Mail mode as well. The minor mode orgstruct-mode makes this
71     possible. [...]
73     When this mode is active and the cursor is on a line that looks to Org like a
74     headline or the first line of a list item, most structure editing commands
75     will work, even if the same keys normally have different functionality in
76     the major mode you are using. If the cursor is not in one of those special
77     lines, Orgstruct mode lurks silently in the shadows. When you use
78     orgstruct++-mode, Org will also export indentation and autofill settings
79     into that mode, and detect item context after the first line of an item.
80 #+end_example
82 *orgstruct* currently does NOT work with /outorg/ and /navi-mode/ (see below for
83 a description of these libraries). To make both libraries work with
84 orgstruct-buffers just like with outshine-buffers, it would be necessary to:
86  1. Structure the file with outshine-style headings (e.g. =;; * Header=)
87  2. Make Orgstruct calculate and set file-local variable =outline-regexp= the
88     way /outshine/ does.
89  3. Make Orgstruct calculate and set file-local variable =outline-level= the
90     way /outshine/ does.
91  4. Make Orgstruct calculate and set file-local variable
92     =outline-promotion-headings= the way /outshine/ does. 
94 Then, maybe after a few minor tweaks in the libraries themselves, /outorg/ and
95 /navi-mode/ wouldn't care if they deal with an orgstruct-buffer or an
96 outshine-buffer.
98 *** Outline with Outshine 
99     :PROPERTIES:
100     :CUSTOM_ID: outline-with-outshine
101     :END:
103 **** History and Credits
104     :PROPERTIES:
105     :CUSTOM_ID: history-and-credits
106     :END:
108 *outshine* is a merge and extension of older extensions for
109 /outline-minor-mode/. More exactly, /outshine/ developed out of the now
110 obsolete =outxxtra.el=, /Thorsten Jolitz's/ modified extension of /Per
111 Abrahamsen's/ =out-xtra.el=. With the blessing of it's (well-known) author
112 /Carsten Dominik/, /Thorsten Jolitz/ could merge the (slightly modified)
113 =outline-magic.el= with =outxxtra.el= and extend them into the new
114 =outshine.el= library. Thus, if you use outline with outshine, you don't need
115 outline-magic and out-xtra anymore. However, outshine does not make either of
116 these two obsolete libraries, since it has a more specialized approach and
117 might not be able to replace them in all cases.
119 Furthermore, `outshine.el' includes functions and keybindings from
120 [[http://emacswiki.org/emacs/OutlineMinorMode][outline-mode-easy-bindings]]. Unfortunately, no author is given for that
121 library, so I cannot credit the person who wrote it.
123 So what is /outshine/? It's an extension library for outline-minor-mode that
124 gives buffers in different major-modes the 'look-and-feel' of Org-mode buffers
125 and enables the use of /outorg/ and /navi-mode/ on them.
127 To sum it up in one sentence:
129 #+begin_verse
130  Outline with Outshine outshines Outline
131 #+end_verse
133 **** Installation
134      :PROPERTIES:
135      :CUSTOM_ID: outshine-installation
136      :END:
138 Download =outshine.el= (or clone the github-repo) and copy it to a location
139 where Emacs can find it:
141 | https://github.com/tj64/outshine           |
142 | git clone git@github.com:tj64/outshine.git |
144 Use this in your '.emacs' to get started:
146 #+begin_src emacs-lisp
147 (require 'outshine)
148 (add-hook 'outline-minor-mode-hook 'outshine-hook-function)
149 #+end_src
151 If you like the functions and keybindings for 'M -<<arrow-key>>' navigation
152 and visibility cycling copied from `outline-mode-easy-bindings', you might
153 want to put the following code into your Emacs init file to have the same
154 functionality/keybindings available in Org-mode too, overriding the less
155 frequently used commands for moving and promoting/demoting subtrees (but
156 clashing with 'org-table' keybindings):
158 #+begin_src emacs-lisp
159 (when (require 'outshine nil 'NOERROR)
160   (add-hook 'org-mode-hook
161             (lambda ()
162               ;; Redefine arrow keys, since promoting/demoting and moving
163               ;; subtrees up and down are less frequent tasks then
164               ;; navigation and visibility cycling
165                 (org-defkey org-mode-map
166                             (kbd "M-<left>") 'outline-hide-more)
167                 (org-defkey org-mode-map
168                             (kbd "M-<right>") 'outline-show-more)
169                 (org-defkey org-mode-map
170                             (kbd "M-<up>") 'outline-previous-visible-heading)
171                 (org-defkey org-mode-map
172                             (kbd "M-<down>") 'outline-next-visible-heading))
173             'append))
174 #+end_src
176 Add this if you (e.g.) always want outline/outshine for emacs-lisp buffers
177 (recommended):
179 #+begin_src emacs-lisp
180 (add-hook 'emacs-lisp-mode-hook 'outline-minor-mode)  
181 #+end_src
183 If you want a different prefix key for outline-minor-mode, insert first
184 (e.g.):
186 #+begin_src emacs-lisp
187  (defvar outline-minor-mode-prefix "\C-c") 
188 #+end_src
190 or whatever you like best to replace the (quite unusable) original prefix
191 "\C-c @". The prefix can only be changed before outline (minor) mode is
192 loaded.
194 **** Outshine's fundamental idea
195      :PROPERTIES:
196      :CUSTOM_ID: fundamental-idea
197      :END:
199 /outshine/ is based on a very simple yet powerful idea, that enables its use
200 in any Emacs major-mode (in theory at least):
202 #+begin_verse
203 Outshine headlines are Org-mode headlines out-commented with =comment-region=
204 #+end_verse
206 Thus, the file at hand must be outline-structured 'the outshine way', i.e.
207 with the headlines being proper Org-mode headlines, marked and outcommented
208 with =comment-region=. As an example, to generate a 3rd level
209 outshine-headline in an Emacs Lisp file, write down
211 : ,-----------------------
212 : | *** Third Level Header 
213 : `-----------------------
215 mark the header line, and apply =comment-region= on it:
217 : ,-----------------------
218 : | ;; *** Third Level Header 
219 : `-----------------------
221 In a LaTeX file, an adequate header will look like this:
223 : ,-----------------------
224 : | % *** Third Level Header 
225 : `-----------------------
227 and in a PicoLisp file like this (always depending of the major-mode specific
228 values of =comment-start=, =comment-end=, =comment-add= and
229 =comment-padding=):
231 : ,-----------------------
232 : | ## *** Third Level Header 
233 : `-----------------------
235 =outshine.el=, =outorg.el= and =navi-mode.el= are all examples of how to
236 structure emacs-lisp source files with outshine-style headlines. 
238 **** Fontification, Navigation and Structure Editing
239      :PROPERTIES:
240      :CUSTOM_ID: fontification-navigation-and-structure-editing
241      :END:
243 After structuring a source code file the 'outshine-way' and loading
244 outline-minor-mode with outshine-extensions, the file will have a very
245 Org-mode like 'look-and-feel'. The headlines (up to level 8) are fontified the
246 same way Org-mode headlines are fontified, and the very specific navigation
247 and structure editing commands of outline-minor-mode as well as their more
248 general Org-mode style counterparts are available:
250 =outline-minor-mode= Minor Mode Bindings:
252 | key       | binding                          |
253 |-----------+----------------------------------|
254 | C-c       | PrefixCommand                    |
255 | <M-down>  | outline-next-visible-heading     |
256 | <M-left>  | outline-hide-more                |
257 | <M-right> | outline-show-more                |
258 | <M-up>    | outline-previous-visible-heading |
259 | <tab>     | outshine-cycle-subtree           |
260 | <backtab> | outshine-cycle-buffer            |
261 | C-c C-a   | show-all                         |
262 | C-c C-b   | outline-backward-same-level      |
263 | C-c C-c   | hide-entry                       |
264 | C-c C-d   | hide-subtree                     |
265 | C-c C-e   | show-entry                       |
266 | C-c C-f   | outline-forward-same-level       |
267 | C-c TAB   | show-children                    |
268 | C-c C-k   | show-branches                    |
269 | C-c C-l   | hide-leaves                      |
270 | C-c RET   | outline-insert-heading           |
271 | C-c C-n   | outline-next-visible-heading     |
272 | C-c C-o   | outline-hide-other               |
273 | C-c C-p   | outline-previous-visible-heading |
274 | C-c C-q   | outline-hide-sublevels           |
275 | C-c C-s   | show-subtree                     |
276 | C-c C-t   | hide-body                        |
277 | C-c C-u   | outline-up-heading               |
278 | C-c C-v   | outline-move-subtree-down        |
279 | C-c C-^   | outline-move-subtree-up          |
280 | C-c '     | outorg-edit-as-org               |
281 | C-c @     | outline-mark-subtree             |
282 | C-c I     | outline-previous-visible-heading |
283 | C-c J     | outline-hide-more                |
284 | C-c K     | outline-next-visible-heading     |
285 | C-c L     | outline-show-more                |
286 | C-c C-<   | outline-promote                  |
287 | C-c C->   | outline-demote                   |
289 ** Subtree and Comment Editing
290    :PROPERTIES:
291    :CUSTOM_ID: comment-editing
292    :END:
293 *** Introduction
294     :PROPERTIES:
295     :CUSTOM_ID: comment-editing-introduction
296     :END:
298     Once a (outshine) source code buffer looks and behaves like an Org-mode
299     buffer, it would be nice to have the full editing power of Org-mode
300     available when editing the (comment) text parts or overall structure of
301     the buffer.
303     Think "reverse Org-Babel": editing of comment-sections or entire subtrees
304     from source code files in temporary Org-mode buffers instead of editing of
305     Org-mode source-blocks in temporary source-code buffers.
307     There are two new libraries available for editing with Org-mode in other
308     major-modes, /outorg/ and /poporg/. Although developed independently with
309     very different implementations, both libraries complement each other very
310     well in their functionality. 
312 *** Outorg
313     :PROPERTIES:
314     :CUSTOM_ID: outorg
315     :END:
317 **** Introduction and Installation
318     :PROPERTIES:
319     :CUSTOM_ID: outorg-introduction-and-installation
320     :END:
322 *outorg* is a library written by /Thorsten Jolitz/ on top of his /outshine/
323 library. Thus, /outorg/ needs /outshine/, and files that are structured with
324 outshine-style headers, otherwise it won't work (note that 'oldschool' Emacs
325 Lisp files with headers matched by =^;;;+= are a special case where outorg
326 works too). 
328 You can download the file (or clone the github-repo) here:
330 | https://github.com/tj64/outorg           |
331 | git clone git@github.com:tj64/outorg.git |
333 /outorg/ requires Org-mode too, thus should be loaded after Org-mode. Insert
335 #+begin_src emacs-lisp
336  (require 'outorg)
337 #+end_src
339 in your .emacs and you are done. 
341 **** Usage
342      :PROPERTIES:
343      :CUSTOM_ID: outorg-usage
344      :END:
346 /outorg's/ main command is
348 :  ,---------------------------
349 :  | C-c ' (outorg-edit-as-org)
350 :  `---------------------------
352 used in source-code buffers where `outline-minor-mode' is activated with
353 `outshine' extensions. The Org-mode edit-buffer popped up by this command
354 has `outorg-edit-minor-mode' activated, a minor-mode with only 2 commands:
356 : ,----------------------------------------
357 : | M-# (outorg-copy-edits-and-exit)
358 : | C-x C-s (outorg-save-edits-to-tmp-file)
359 : `----------------------------------------
361 If you want to insert Org-mode source-code or example blocks in
362 comment-sections, simply outcomment them in the outorg-edit buffer before
363 calling `outorg-copy-edits-and-exit'.
365 Thus, with point inside a subtree or on a subtree header, pressing =C-c '
366 (outorg-edit-as-org)= will open this subtree in a temporary Org-mode edit
367 buffer, with all out-commented parts in the original buffer uncommented, and
368 all source code parts enclosed in Org-mode source blocks. 
370 When =outorg-edit-as-org= is called with a prefix =C-u=, the whole source-code
371 buffer will be transformed into Org-mode and offered for editing in a
372 temporary Org-mode buffer, all headlines folded except the subtree where point
373 was in.
375 If the original-buffer was read-only, the user is asked if he wants to make it
376 writable for the Org-mode editing. If he answers yes, the buffer can be
377 edited, but will be set back to read-only again after editing is finished.
379 To avoid accidental loss of edits, the temporary outorg-edit-buffer is backed
380 up in the OS =/tmp= directory. During editing, the outorg-edit-buffer can be
381 saved as usual with =save-buffer= via  =C-x C-s=. Even when killed by
382 accident, that last state of the outorg-edit-buffer will be saved and can be
383 recovered. 
385 When done with editing in Org-mode, =M-# (Meta-key and #)= is used to call
386 =outorg-copy-edits-and-exit=, a command that orderly exits the edit-buffer by
387 converting the (modified) comment-sections back to comments and extracting the
388 source-code parts out of the Org-mode source-code blocks.
390 Please note: /outorg/ is line-based, it only works with 'one-line' comments,
391 i.e. with comment-sections like those produced by `comment-region' (a command
392 that comments or uncomments each line in the region). Those special multi-line
393 comments found in many programming languages are not recognized and lead to
394 undefined behaviour.
396 **** Outorg vs Poporg
397      :PROPERTIES:
398      :CUSTOM_ID: outorg-vs-poporg
399      :END:
401 /outorg/ works on subtrees (or whole buffers). 
403 One advantage of this is that there is always a complete subtree (-hierarchy)
404 in the outorg-edit-buffer, thus not only the Orgmode editing functionality can
405 be applied, but also its export facilities and many other commands that act on
406 headlines or subtrees. As an example, in order to produce the nice README.txt
407 files for the github-repos of /outshine/, /outorg/ and /navi-mode/, I simply
408 called =outorg-edit-as-org= on the first 1st-level-headline of the source-code
409 files (the file header comment-sections) and exported the subtree to ASCII.
411 One disadvantage of this is that comment-strings of (e.g. emacs-lips)
412 functions cannot be edited comfortably, since after transformation of the
413 source-code buffer they end up inside Org-mode source-code blocks - as
414 comment-strings, just like before. 
416 Enters /poporg/. It will be described in much detail in the next section, but
417 it can already be mentioned here that it does exactly what /outorg/ cannot do
418 well - Org-mode editing of atomic, isolated comment-strings, no matter where
419 they are found in the source code buffer. And it is, in contrast to /outorg/,
420 completely independent from outline structuring with e.g. /outshine/ or
421 /orgstruct/. 
423 *** Poporg
424     :PROPERTIES:
425     :CUSTOM_ID: poporg
426     :END:
428 [NOTE: This section of the tutorial is copied from
429 [[https://github.com/QBobWatson/poporg]], where you can find the =poporg.el= file too,
430 and only slightly modified]
432 **** Introduction
433      :PROPERTIES:
434      :CUSTOM_ID: poporg-introcuction
435      :END:
437 *poporg* is a small Emacs lisp project written by /François Pinard/ to
438 help editing program strings and comments using Org mode (or any other
439 major mode).  This can be useful as it is often more convenient to
440 edit large pieces of text, like Emacs lisp or Python docstrings, in an
441 org-mode buffer instead of in a comment or a string.
443 Emacs does not easily handle multiple major modes in a single buffer.
444 So far many solutions have been implemented, with varying degrees of
445 success, but none is perfect.  The *poporg* approach avoids the problem
446 by extracting the text from the comment or the string from a buffer
447 using a major programming mode, into a separate buffer to be edited in
448 a text mode, but containing only that comment or that string.  Once
449 the edit is completed, the modified comment or string gets
450 re-integrated in the buffer containing the program, replacing the
451 original contents.
453 The main utility of this package is its ability to handle prefixes
454 automatically.  For comments, it finds all contiguous nonempty
455 comments on their own line, and strips the common prefix before
456 inserting into the editing buffer (see =poporg-comment-skip-regexp=).
457 For strings, it checks if there is consistent indentation for the
458 whole string (the opening delimiter of the string can only have
459 whitespace before it), and uses that as the common prefix.  For
460 regions, it just uses a naive common prefix.  When placing the edited
461 text back in context, it adds the common prefix again, potentially
462 stripping any trailing whitespace (see
463 =poporg-delete-trailing-whitespace=).  It can even adjust the fill
464 column in the editing buffer to account for indentation (see
465 =poporg-adjust-fill-column=).
467 **** Installation
468      :PROPERTIES:
469      :CUSTOM_ID: poporg-installation
470      :END:
472 To install *poporg*, move file =poporg.el= to a place where Emacs will
473 find it.  You might byte-compile the file if you want.  There are also
474 [[https://github.com/dimitri/el-get][El-Get]] and [[http://melpa.milkbox.net/][MELPA]] recipes.
476 To use *poporg*, you need to pick some unused keybinding and add a few
477 lines to your =~/.emacs= file, such as:
479 #+BEGIN_SRC emacs-lisp
480   (autoload 'poporg-dwim "poporg" nil t)
481   (global-set-key (kbd "C-c \"") 'poporg-dwim)
482 #+END_SRC
484 It is important that this be a global keybinding, or at least that the
485 command =poporg-dwim= be available from both the programming and the
486 text editing buffers.
488 **** Usage
489      :PROPERTIES:
490      :CUSTOM_ID: poporg-usage
491      :END:
493 The command =poporg-dwim= searches for a nearby comment or string (see
494 =poporg-find-string-or-comment=) and, upon finding one, it opens an
495 empty buffer in a new window with its contents available for editing.
496 If the region is active then =poporg-dwim= inserts the region into the
497 buffer instead.  The original text is grayed out and set read-only to
498 prevent editing in two places at once.  After editing, running
499 =poporg-dwim= again from the editing buffer kills the editing buffer and
500 inserts the edited text back into its original context.
502 Hopefully =poporg-dwim= will do what you expect in most situations.  It
503 uses the buffer's syntax table for parsing, so it should adapt well to
504 most modes (including sextuple-quoted strings in Python).  If you run
505 =poporg-dwim= in the vicinity of a grayed-out region that you are
506 editing in another buffer, it pops to that buffer.  It has the
507 following caveats:
509  1. It does not understand empty strings.
510  2. It cannot deal very well with comments with ending delimiters.
512 For example, in c-mode, comments start with =/*= and end with =*/=.  This
513 is a problem because poporg needs a common prefix for all lines.  In
514 order to make poporg understand these comments, write them on separate
515 lines like this:
517 #+BEGIN_SRC c
518  /*
519   * Comments go here.  Not on a line with the opening delimiter or the
520   * closing delimiter.
521   */
522 #+END_SRC
524 In this situation poporg will ignore the first and last lines because
525 they are empty except for comment delimiters, and detect the common
526 prefix =__= or =__*_= for the middle lines, depending on whether the =*=
527 character is matched by =poporg-comment-skip-regexp=.
529 You will probably want to customize =poporg-edit-hook=, since that is
530 where the major mode of the edit buffer is set.  The minor mode
531 =poporg-mode= is activated in the edit buffer.  It has one keybinding by
532 default, which remaps =save-buffer= (C-x C-s) to =poporg-edit-exit=.  You
533 can add additional keybindings to =poporg-mode-map=.  To save an edit,
534 from the editing buffer run =poporg-edit-exit= or =poporg-dwim=; to abort
535 the edit simply kill the buffer.
537 ** Remote Buffer Control
538    :PROPERTIES:
539    :CUSTOM_ID: remote-buffer-control
540    :END:
542 While visibility-cycling and outline-navigation commands make it very
543 convenient to work even with big Org-mode or outshine buffers, it can't be
544 denied that a read-only "twin-buffer" with one-key command-bindings,
545 exclusively for navigation and high-level structure editing of the associated
546 original-buffer, can be even more convenient.
548 Enters /navi-mode/, a major-mode by /Thorsten Jolitz/ derived from and
549 inspired by /occur-mode/ (and, to a certain extend, the =org-goto= command).
550 Just like /outorg/, /navi-mode/ depends on /outshine/ and works only with
551 source-code files structured with 'outshine-style' outline-headers. It does
552 work with Org-mode files and 'oldschool' Emacs Lisp files too, though. 
554 A /navi-buffer/ is a kind of "remote-control" for its associated
555 /original-buffer/. It offers a vast amount of views on the /original-buffer/
556 via predefined occur-searches that combine headlines and
557 (programming-language specific) keywords. It further allows many frequent
558 actions on the subtree at point to be triggered directly from the
559 /navi-buffer/, without (visibly) switching to the /original-buffer/ where the
560 actions take place. 
562 A special feature of /navi-mode/ is its customizability. It predefines all
563 ASCII printing characters as keybindings for the =navi-generic-command=, and
564 users can therefore map their user-defined regexp-searches (customizable
565 variable =navi-keywords=) to any of the many free one-key bindings (in
566 customizable variable =navi-key-mappings=). These customizations are made by
567 programming-language, thus the Emacs community could work out default
568 'alists' for many languages that then may be used and modified by the users. 
570 /navi-mode's/ author /Thorsten Jolitz/ already worked out two configurations,
571 one for Emacs Lisp and the other for PicoLisp. You could use them as
572 inspiration for a configuration of your favorite programming language - and
573 send these 'alists' to him so that he can include them in the library. The
574 more predefined sets of keyword searches there are, the easier to use
575 /navi-mode/ with many languages.
577 *** Navi-mode
578     :PROPERTIES:
579     :CUSTOM_ID: navi-mode
580     :END:
582 **** About navi-mode
583      :PROPERTIES:
584      :CUSTOM_ID: about-navi-mode
585      :END:
587 /navi-mode/ implements extensions for occur-mode. You can think of a
588 navi-buffer as a kind of 'remote-control' for an (adequately)
589 outline-structured original-buffer. It enables quick navigation and basic
590 structure editing in the original-buffer without (necessarily) leaving the
591 navi-buffer. When switching to the original-buffer and coming back after some
592 modifications, the navi-buffer is always reverted (thus up-to-date).
594 Besides the fundamental outline-heading-searches (8 outline-levels) and the 5
595 basic keyword-searches (:FUN, :VAR, :DB, :OBJ and :ALL), all languages can
596 have their own set of searches and keybindings (see =navi-key-mappings= and
597 =navi-keywords=). Heading-searches and keyword-searches can be combined,
598 offering a vast amount of possible 'views' at the original-buffer.
600 **** Installation
602 Download (or clone the github-repos of) the three required libraries
604 | `navi-mode.el' | https://github.com/tj64/navi           |
605 |                | git clone git@github.com:tj64/navi.git |
606 | `outshine.el'  | https://github.com/tj64/outshine       |
607 | `outorg.el'    | https://github.com/tj64/outorg         |
609 and put them in a place where Emacs can find them (on the Emacs 'load-path').
610 Follow the installation instructions in =outshine.el= and =outorg.el=.
612 Install =navi-mode.el= by adding
614 #+begin_src emacs-lisp
615  (require 'navi-mode)
616 #+end_src
618 to your .emacs file. 
621 **** Usage
622      :PROPERTIES:
623      :CUSTOM_ID: navi-mode-usage
624      :END:
626 For /navi-mode/ to work, the original-buffer must be outline-structured 'the
627 outshine way', i.e. with the headlines being proper Org-mode headlines, marked
628 and outcommented with /comment-region/ (but oldschool Emacs Lisp headers like
629 =;;; header level 1= work too) . 
631 The second assumption is that /outline-minor-mode/ is activated in the
632 original-buffer and /outshine.el/ loaded like described in its installation
633 instructions (except for Org-mode files). 
635 When these pre-conditions are fulfilled (/outorg.el/ must be loaded too), you
636 can use =M-s n (navi-search-and-switch)= to open a /navi-buffer/ and
637 immediately switch to it. The new navi-buffer will show the first-level
638 headings of the /original-buffer/, with point at the first entry.
640 You can then:
642  - Show headlines (up-to) different levels:
644 | key     | command            | function-name        |
645 |---------+--------------------+----------------------|
646 | 1 ... 8 | show levels 1 to 8 | navi-generic-command |
648  - Navigate up and down in the search results shown in the navi-buffer:
650 | key | command   | function-name       |
651 |-----+-----------+---------------------|
652 | p   | previous  | occur-prev          |
653 | n   | next      | occur-next          |
654 | DEL | down page | scroll-down-command |
655 | SPC | up page   | scroll-up-command   |
657  - Revert the navi-buffer (seldom necessary), show help for the user-defined
658    keyword-searches, and quit the navi-buffer and switch-back to the
659    original-buffer:
661 | key | command                   | function-name        |
662 |-----+---------------------------+----------------------|
663 | g   | revert buffer             | navi-revert-function |
664 | h   | show help                 | navi-show-help       |
665 | q   | quit navi-mode and switch | navi-quit-and-switch |
667  - Switch to the original-buffer and back to the navi-buffer, display an
668    occurrence in the original-buffer or go to the occurrence:
670 | key     | command                | function-name                     |
671 |---------+------------------------+-----------------------------------|
672 | M-s n   | launch navi-buffer     | navi-search-and-switch            |
673 | M-s s   | switch to other buffer | navi-switch-to-twin-buffer        |
674 | M-s M-s |                        |                                   |
675 | s       |                        |                                   |
676 | d       | display occurrence     | occur-mode-display-occurrence     |
677 | o       | goto occurrence        | navi-goto-occurrence-other-window |
679  - Structure editing on subtrees and visibility cycling
681 | key       | command                        | function-name          |
682 |-----------+--------------------------------+------------------------|
683 | TAB       | cycle subtrees                 | navi-cycle-subtree     |
684 | <backtab> | cycle buffer                   | navi-cycle-buffer      |
685 | +         | Demote Subtree                 | navi-demote-subtree    |
686 | -         | promote subtree                | navi-promote-subtree   |
687 | \^        | move up subtree (same level)   | navi-move-up-subtree   |
688 | <         | move down subtree (same level) | navi-move-down-subtree |
690  - Miscellaneous actions on subtrees
692 | key | command                    | function-name                     |
693 |-----+----------------------------+-----------------------------------|
694 | m   | mark subtree               | navi-mark-subtree-and-switch      |
695 | c   | copy subtree               | navi-copy-subtree-to-register-s   |
696 | k   | kill subtree               | navi-kill-subtree                 |
697 | y   | yank killed/copied subtree | navi-yank-subtree-from-register-s |
698 | u   | undo last change           | navi-undo                         |
699 | r   | narrow to subtree          | navi-narrow-to-subtree            |
700 | w   | widen                      | navi-widen                        |
701 | l   | query-replace              | navi-query-replace                |
702 | i   | isearch                    | navi-isearch                      |
703 | e   | edit as org (outorg)       | navi-edit-as-org                  |
705  - Furthermore, there are five (semantically) predefined keyword-searches:
707 | key | keyword-symbol | searches for               |
708 |-----+----------------+----------------------------|
709 | f   | :FUN           | functions, macros etc.     |
710 | v   | :VAR           | vars, consts, customs etc. |
711 | x   | :OBJ           | OOP (classes, methods etc) |
712 | b   | :DB            | DB (store and select)      |
713 | a   | :ALL           | all                        |
716  - And (potentially) many more user-defined keyword-searches
717 (example Emacs Lisp):
719 | key | keyword-symbol | searches for |
720 |-----+----------------+--------------|
721 | F   | :defun         | (defun       |
722 | V   | :defvar        | (defvar      |
723 | C   | :defconst      | (defconst    |
724 | G   | :defgroup      | (defgroup    |
725 | U   | :defcustom     | (defcustom   |
726 | A   | :defadvice     | (defadvice   |
727 | M   | :defmacro      | (defmacro    |
728 | E   | :defface       | (defface     |
729 | S   | :defstruct     | (defstruct   |
730 | L   | :defclass      | (defclass    |
732  - Headline-searches and keyword-searches can be combined, e.g.
734 : ,------
735 : | C-2 f 
736 : `------
738 in a /navi-buffer/ associated to an Emacs Lisp source file shows all headlines
739 up-to level 2 as well as all function, macro and advice definitions in the
740 original-buffer,
742 : ,------
743 : | C-5 a 
744 : `------
746 shows all headlines up-to level 5 as well as all functions, variables,
747 classes, methods, objects, and database-related definitions. The exact meaning
748 of the standard keyword-searches 'f' and 'a' must be defined with a regexp in
749 the customizable variable `navi-keywords' (just like the user-defined
750 keyword-searches).
752 * Screencasts 
753   :PROPERTIES:
754   :CUSTOM_ID: screencasts
755   :END:
757 There are some screencasts on Youtube that show the libraries mentioned in
758 this article in action:
760 | topic                                                       | url                                         |
761 |-------------------------------------------------------------+---------------------------------------------|
762 | <30>                                                        | <30>                                        |
763 | Modern conventions for Emacs Lisp files                     | https://www.youtube.com/watch?v=nqE6YxlY0rw |
764 | Exploring Bernt Hansen's Org-mode tutorial with 'navi-mode' | https://www.youtube.com/watch?v=nqE6YxlY0rw |
765 | Exploring my dot emacs file with 'navi-mode'                | https://www.youtube.com/watch?v=nqE6YxlY0rw |
766 | Exploring a PicoLisp source file with GNU Emacs navi-mode   | https://www.youtube.com/watch?v=MYJvQ-5dvK8 |
768 'Modern conventions for Emacs Lisp files' is probably the video you should
769 watch first, it explores 'navi-mode.el' itself as an Emacs Lisp library
770 structured the 'outshine way', and shows the use of outline-minor-mode,
771 outorg, poporg and navi-mode on such a file. And is has the best background
772 music.