FastNav

Last edit

Summary: Rückgängig gemacht auf den Stand vom 2013-08-24 11:21 UTC

Changed:

< * It's built on top of iWikiModes and benefits from all of iWikiModes's integration functions.

to

> * It's built on top of isearch and benefits from all of isearch's integration functions.

Changed:

< As of jumping to beginning of words - this seems to be simple to implement, although it may be much more expensive than per-character sprinting, since it will have to WikiModes through much more text. I'll be glad to accept pull requests with this feature!

to

> As of jumping to beginning of words - this seems to be simple to implement, although it may be much more expensive than per-character sprinting, since it will have to search through much more text. I'll be glad to accept pull requests with this feature!


Inspired by zap-to-char, this library defines different routines operating on the next/previous N’th occurrence of a character. When invoking one of these commands, the user is interactively queried for a character while the potential target positions are highlighted.

For example, META-s (fastnav-jump-to-char-forward) highlights the next occurrences of each character and prompts for one. Once the user picks a char, the point is moved to that position. Subsequent invocations of META-s before picking a character increases N, that is, the second, third, etc. occurrences are highlighted and targeted.

The sprint-forward/backward commands apply iterative jumping until return/C-g is hit, making it possible to reach any point of the text with just a few keystrokes.

To use it, simply install fastnav package from Marmalade repo, and add something like this to your emacs initialization file:

    (require 'fastnav)
    (global-set-key "\M-z" 'fastnav-zap-up-to-char-forward)
    (global-set-key "\M-Z" 'fastnav-zap-up-to-char-backward)
    (global-set-key "\M-s" 'fastnav-jump-to-char-forward)
    (global-set-key "\M-S" 'fastnav-jump-to-char-backward)
    (global-set-key "\M-r" 'fastnav-replace-char-forward)
    (global-set-key "\M-R" 'fastnav-replace-char-backward)
    (global-set-key "\M-i" 'fastnav-insert-at-char-forward)
    (global-set-key "\M-I" 'fastnav-insert-at-char-backward)
    (global-set-key "\M-j" 'fastnav-execute-at-char-forward)
    (global-set-key "\M-J" 'fastnav-execute-at-char-backward)
    (global-set-key "\M-k" 'fastnav-delete-char-forward)
    (global-set-key "\M-K" 'fastnav-delete-char-backward)
    (global-set-key "\M-m" 'fastnav-mark-to-char-forward)
    (global-set-key "\M-M" 'fastnav-mark-to-char-backward)
    (global-set-key "\M-p" 'fastnav-sprint-forward)
    (global-set-key "\M-P" 'fastnav-sprint-backward)

Below is an screenshot showing how the first occurences of each character are highlighted:

FastNavScreenshot

Discussion

[[new:LeWang:2012-10-21 14:18 UTC]] I developed JumpChar? (https://github.com/lewang/jump-char) as a replacement iy-goto-char. It ended up having very similar functionality to FastNav with some clear advantages:

However a drawback is that jumpchar focuses on jumping to characters and does not offer any of FastNav’s other functionalities.

Nice. Is it possible to add memory to this thing? Like, ‘M-s RET’ jumps forward to the character previously entered.

I don’t see the point. Why cannot you just hit ‘M-s x’ if x is the character previously entered?

I like the idea. You should prefix your functions with fastnav- to avoid polluting the global namespace.

Amúgy szép munka. ;)

This is very efficient. I wonder, though, if a function could be added that jumps to the Nth word that begins with a specified character (so it only highlights letters at the beginning of words). Often I want to jump several words forward or backward without having to guess which numerical argument to put in. Anyone know of a function out there that already does this?

Updated (package.el compatible and prefixed function names) version is available at https://github.com/gleber/fastnav.el and has been uploaded to both ELPA and Marmalade

Why don’t you use kill-region instead of delete-region in the “zap-up-to-char-” functions so that the region is also copied to the kill ring?

Newest version at https://github.com/gleber/fastnav.el contains changes which replaces delete-region with kill-region.

As of jumping to beginning of words - this seems to be simple to implement, although it may be much more expensive than per-character sprinting, since it will have to search through much more text. I’ll be glad to accept pull requests with this feature!


CategoryKeys, CategoryEditing