Skip to content

emacsmirror/spatial-navigate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Emacs Spatial Navigate

This implements directional navigation shown here.

You may navigate in 4 directions, jumping over contiguous regions of white-space or populated space.

To get an idea how this can be useful it's best to see the demo or try it for yourself.

Available via melpa.

Motivation

While Emacs has many available methods of navigating based on document structure, there are times when it's quick & predictable to move the cursor in any direction jumping between contiguous regions of white-space (or non white-space).

This isn't intended to be better than other methods of navigating between parts of a document, it's just an alternative which you might find useful.

Note

Single spaces between words are not counted as white-space.

Features

  • Navigate in 4 directions.
  • Expose functions for both box & bar cursors, to handle white-space surrounding the cursor logically.

Usage

This is not a minor mode, you only need to bind the functions to key bindings.

Available functions:

  • spatial-navigate-backward-vertical-box
  • spatial-navigate-forward-vertical-box
  • spatial-navigate-backward-horizontal-box
  • spatial-navigate-forward-horizontal-box
  • spatial-navigate-backward-vertical-bar
  • spatial-navigate-forward-vertical-bar
  • spatial-navigate-backward-horizontal-bar
  • spatial-navigate-forward-horizontal-bar

For vertical motion, the box functions detect white space in front and behind the cursor, while the bar functions only detect white-space at the cursor and behind it (behaving as you might expect when the cursor draws as a bar).

Example with global key bindings.

(global-set-key (kbd "<M-up>") 'spatial-navigate-backward-vertical-bar)
(global-set-key (kbd "<M-down>") 'spatial-navigate-forward-vertical-bar)
(global-set-key (kbd "<M-left>") 'spatial-navigate-backward-horizontal-bar)
(global-set-key (kbd "<M-right>") 'spatial-navigate-forward-horizontal-bar)

Example with evil-mode key bindings.

(define-key evil-normal-state-map (kbd "M-k") 'spatial-navigate-backward-vertical-box)
(define-key evil-normal-state-map (kbd "M-j") 'spatial-navigate-forward-vertical-box)
(define-key evil-normal-state-map (kbd "M-h") 'spatial-navigate-backward-horizontal-box)
(define-key evil-normal-state-map (kbd "M-l") 'spatial-navigate-forward-horizontal-box)
(define-key evil-insert-state-map (kbd "M-k") 'spatial-navigate-backward-vertical-bar)
(define-key evil-insert-state-map (kbd "M-j") 'spatial-navigate-forward-vertical-bar)
(define-key evil-insert-state-map (kbd "M-h") 'spatial-navigate-backward-horizontal-bar)
(define-key evil-insert-state-map (kbd "M-l") 'spatial-navigate-forward-horizontal-bar)

Customization

spatial-navigate-wrap-horizontal-motion: nil
Skip blank lines when horizontal motion reaches line bounds.
spatial-navigate-region-line-vertical-motion: nil

Select whole lines when extending an active region vertically.

When the point is at column zero and there is an active region, adjust motion to ensure the motion selects an entire block of text.

This prevents the last line from being unselected after a motion.

About

Directional navigation between blank-space blocks

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

  •  

Packages

 
 
 

Contributors