Loccur is an amazing tool to quickly navigate in a file. It is a minor mode for Emacs acting like occur but w/o creating a new window. It just hides all the text excepting lines containing matches.
Add to your .emacs
or .emacs.d/init.el
following lines:
(setq package-archives '(("gnu" . "http://elpa.gnu.org/packages/")
("melpa" . "http://melpa.milkbox.net/packages/")))
Press M-x
in GNU Emacs and write list-packages
. Find the loccur
in the list of packages and press i
to select this package, x
to install the package.
Better to see it once:
To use it, add the following to your .emacs file:
(require 'loccur)
;; defines shortcut for loccur of the current word
(define-key global-map [(control o)] 'loccur-current)
;; defines shortcut for the interactive loccur command
(define-key global-map [(control meta o)] 'loccur)
;; defines shortcut for the loccur of the previously found word
(define-key global-map [(control shift o)] 'loccur-previous-match)
Now you can point the cursor to the word and press Ctrl+o
to hide all lines except those containing this word. Moving cursor to the required line and pressing Ctrl+o
again will shows all the text. The good thing about this mode is what you can navigate through the buffer easily. Ctrl+Shift+o
will repeat last search.
Below is the list of interactive commands available for user:
loccur
interactively asks user for regexp to search or toggle search off (ifloccur-mode
is already enabled)loccur-current
searches for the current word under the cursorloccur-previous-match
repeat previousloccur
commandloccur-no-highlight
is the same asloccur
but not highlighting matchesloccur-toggle-highlight
toggles highlighting of matchesloccur-isearch
: incremental occur (more details below)
loccur-jump-beginning-of-line
variable specifies if move the cursor to the beginning of the matching line. Defaultnil
loccur-highlight-matching-regexp
variable wheneverloccur
should highlight matching words. Defaultt
.loccur-face
face to be used while highlighting. Default points toisearch
face.
The loccur-isearch
command filters buffer lines incrementally as you
type a search string. It can also be called when Isearch is already
active to turn filtering on or off. For the latter functionality, you
should bind the command in isearch-mode-map
, for example as follows:
(define-key global-map (kbd "M-s C-o") 'loccur-isearch)
(define-key isearch-mode-map (kbd "C-o") 'loccur-isearch)
You can contribute to loccur in one of the following ways.
- Submit a bug report
- Submit a feature request
- Submit a simple pull request (with changes < 15 lines)
Since loccur is a part of GNU ELPA, it is copyrighted by the Free Software Foundation, Inc.. Therefore in order to submit nontrivial changes (with total amount of lines > 15), one needs to to grant the right to include your works in GNU Emacs to the FSF.
For this you need to complete this form, and send it to [email protected]. The FSF will send you the assignment contract that both you and the FSF will sign.
For more information one can read here to understand why it is needed.
As soon as the paperwork is done one can contribute to loccur with bigger pull requests. Note what pull requests without paperwork done will not be accepted, so please notify the maintainer if everything is in place.