Coder Social home page Coder Social logo

iy-go-to-char's Introduction

Stories in Ready

iy-go-to-char.el

Go to next CHAR which is similar to "f" and "t" in vim


License GPLv2 MELPA

This package defines the function iy-go-to-char which behaves like "f" in vim, and iy-go-up-to-char like "t" in vim. It reads a char and go the next Nth occurence of the char. User can continue such search using that char key.

To use, make sure this file is on your load-path and put the following in your .emacs file:

(require 'iy-go-to-char)

To make iy-go-to-char works better with multiple-cursors, add iy-go-to-char-start-pos to mc/cursor-specific-vars when mc is loaded:

(add-to-list 'mc/cursor-specific-vars 'iy-go-to-char-start-pos)

Then you can bind functions like:

(global-set-key (kbd "C-c f") 'iy-go-to-char)
(global-set-key (kbd "C-c F") 'iy-go-to-char-backward)
(global-set-key (kbd "C-c ;") 'iy-go-to-or-up-to-continue)
(global-set-key (kbd "C-c ,") 'iy-go-to-or-up-to-continue-backward)

Or if you prefer up-to (vim "t") versions:

(global-set-key (kbd "C-c f") 'iy-go-up-to-char)
(global-set-key (kbd "C-c F") 'iy-go-up-to-char-backward)

You also can bind go-to methods and up-to methods to different keys.

Except repeating the char key, followings keys are defined before quitting the search (which can be disabled by setting iy-go-to-char-override-local-map to nil):

X -- where X is the char to be searched. Repeating it will search forward the char. Can be disabled through iy-go-to-char-continue-when-repeating

; -- search forward the char, customizable: iy-go-to-char-key-forward, iy-go-to-char-use-key-forward

, -- search backward the char, customizable: iy-go-to-char-key-backward, iy-go-to-char-use-key-backward

C-g -- quit

C-s -- start isearch-forward using char as initial search string

C-r -- start isearch-backward using char as initial search string

C-w -- quit and kill region between start and current point. If region is activated before search, then use the original mark instead of the start position.

M-w -- quit and save region between start and current point. If region is activated before search, use the mark instead of start position.

All other keys will quit the search. Then the key event is intepreted in the original environment before search.

if the search quits because of error or using "C-g", point is set back to the start position. Otherwise, point is not change and the start position is set as marker. So you can use "C-x C-x" back to that position.

iy-go-to-char-backward search backward by default. Also the search can cross lines. To continue search last char, use iy-go-to-char-continue and iy-go-to-char-continue-backward.

Change Log

2014-10-29 (3.2.2)

  • Add options iy-go-to-char-use-key-forward, iy-go-to-char-use-key-backward and iy-go-to-char-continue-when-repeating to toggle the feature that continuing search by repeat typing a single key.
  • Add option iy-go-to-char-override-local-map to disable the temporary map after activate iy-go-to-char.

2013-04-28 (3.2.1)

  • Fix documentations.
  • Add up-to versions: iy-go-up-to-char, iy-go-up-to-char-backward, iy-go-up-to-char-continue and iy-go-up-to-char-continue-backward.

2013-04-28 (3.1)

  • Better integration with multiple-cursors.
  • Refactoring documentations.

2013-04-08 (3.0)

  • When jump is started backward (with negative parameter, or iy-go-to-char-backward). Repeating continues the search backward. Also iy-go-to-char-key-forward jumps with the same direction when jump is started, and iy-go-to-char-key-backward jumps to reverse direction.

2013-03-25 (2.1)

  • Fix a but that I forget to set mc--this-command

2013-03-25 (2.0)

  • Use overriding-local-map to setup keymap
  • multiple-cursors compatible

2012-04-16 (1.1)

  • fix C-s/C-r to enter isearch

Function Documentation

(iy-go-to-char-done)

Finish iy-go-to-char-mode.

(iy-go-to-char-quit)

Quit iy-go-to-char-mode.

(iy-go-to-char-pass-through)

Finish iy-go-to-char-mode and invoke the corresponding command.

(iy-go-to-char-isearch)

Start isearch using the char.

(iy-go-to-char-isearch-backward)

Start isearch backward using the char.

(iy-go-to-char-kill-region)

Kill region between jump start position and current position.

(iy-go-to-char-kill-ring-save)

Save region between jump start position and current position.

(iy-go-to-char N CHAR)

Move forward to N occurrences of CHAR.

Uses keymap iy-go-to-char-keymap, which is not currently defined.

Typing key of CHAR will move to the next occurence of CHAR.

Typing iy-go-to-char-key-forward will move to the next occurence of CHAR.

Typing iy-go-to-char-key-backward, will move to the previous occurence of CHAR.

Typing M-x iy-go-to-char-quit will quit and return to the original point.

Typing M-x iy-go-to-char-isearch or M-x iy-go-to-char-isearch-backward] will start isearch using CHAR.

Typing M-x iy-go-to-char-kill-region or M-x iy-go-to-char-kill-ring-save will kill/copy between current point and the start point.

Unless quit using M-x iy-go-to-char-quit or the region is activated before searching, the start point is set as mark.

(iy-go-to-char-backward N CHAR)

Move backward to N occurence of CHAR.

Uses keymap iy-go-to-char-keymap, which is not currently defined.

Typing key of CHAR will move to the previous occurence of CHAR.

Typing iy-go-to-char-key-forward moves to the next occurrence of CHAR.

Typing iy-go-to-char-key-backward, moves to the previous occurrence of CHAR.

Typing M-x iy-go-to-char-quit will quit and return to the original point.

Typing M-x iy-go-to-char-isearch or M-x iy-go-to-char-isearch-backward] will start isearch using CHAR.

(iy-go-up-to-char N CHAR)

Move forward to N occurrences of CHAR. Like iy-go-to-char but jump up to the CHAR so it is not included in the region between search start position and current point.

(iy-go-up-to-char-backward N CHAR)

Move backward to N occurrences of CHAR. Like iy-go-to-char-backward but jump up to the CHAR so it is not included in the region between search start position and current point.

(iy-go-to-or-up-to-continue N &optional STOP-POSITION)

Continue last iy-go-to-char or iy-go-to-char-backward by N steps. Set STOP-POSITION to overwrite the last used stop position strategy.

(iy-go-to-or-up-to-continue-backward N &optional STOP-POSITION)

Continue last iy-go-to-char or iy-go-to-char-backward by N steps. Set STOP-POSITION to overwrite the last used stop position strategy.

(iy-go-to-char-continue N)

Continue last iy-go-to-char or iy-go-to-char-backward by N steps.

(iy-go-to-char-continue-backward N)

Continue last iy-go-to-char or iy-go-to-char-backward by N steps.

(iy-go-up-to-char-continue N)

Continue last iy-go-up-to-char or iy-go-up-to-char-backward by N steps.

(iy-go-up-to-char-continue-backward N)

Continue last iy-go-up-to-char or iy-go-up-to-char-backward by N steps.


Markdown README file generated by make-readme-markdown.el

iy-go-to-char's People

Contributors

doitian avatar mgalgs avatar waffle-iron avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

iy-go-to-char's Issues

一个有关跳转后, 复制的 bug.

好吧, 既然知道你是谁, 我就不用我的二流英文跟你交流了。

发现一个跳转到指定字符之后,无法立即复制的 Bug.

假设存在这样一段 Ruby 代码:

'I_love_you'.split('_')                         # => ['I', 'love', 'you']

起始位置在 ] 后面, 我现在希望复制 # => ['I', 'love', 'you'], 我的做法是:
(下面都是通过快捷键操作, 为了方便解释问题, 写出命令 )
M-x iy-go-to-char-backward, 输入 #, 光标跳转到 # 前面。
M-x set-mark-command
M-x end-of-visual-line, 光标跳转到行尾。
然后 M-w 拷贝文本。

这个时候, 找个地方粘帖之前复制的文本, 会发现, 剪贴板是空的。

以上操作,如果没有执行 iy-go-to-char-backward, 没有任何问题。

谢谢。

`last-command' exposes implementation of the package

Hello,

thanks for sharing this useful package.

There is a problem with the value of last-command after having executed any command from this package. The value of last-command will be the internal iy-go-to-char--command instead of iy-go-to-char or any other command from the interface of the package. This is a problem when writing a new command that builds on this package.

Thanks for your attention.

Add ability to terminate search mode explicitly

While ; and , are nice, easily reachable keys that Vim has made standard, they're also characters which you commonly want to insert, especially when operating in multiple-cursors mode. Thus, terminating the search mode explicitly would be a useful thing. I tried doing it myself, by

(eval-after-load 'iy-go-to-char 
  (lambda () 
    (define-key iy-go-to-char-keymap (kbd "RET") 'iy-go-to-char-done)))

but it doesn't work. The function is called, but it doesn't stop processing there and still passes through to the normal command bound to RET. Since I know very little about the command loop, and it's not exactly a perfectly-documented area, I gave up trying to make it work.

Feature request: make `iy-go-to-char--override-local-map` optional

Hello,

thanks for sharing this package.

It would be useful if users could disable the overriding of C-w, M-w, etc. as implemented by iy-go-to-char--override-local-map. The new bindings can be useful, but some users -- like me -- would prefer a simpler interface that doesn't require them to press C-g.

Thanks for your attention.

Numeric arguments behave unintuitively

As far as I can tell giving iy-go-to-char a numeric argument n behaves as follows:

  1. It always searches forward for the abs(n)-th occurence of the character. One might reasonably expect positive n to search forward and negative n to search backward.
  2. Upon repetition, that either by retyping the character or by typing ;, it moves by one occurence. The move is forward if n>0 and backwards if n<0.

Possibly the most consistent behavior possible would be:

  • Both the first jumps and repetitions go forward by n occurences. Here "forward n occurences" means "backwards abs(n) occurences" when n is negative.

But I see the value of point 2 above: you might include a count for the first search but if that didn't get you where you wanted to go, you probably want to adjust by one occurence forwards or backwards. But point 1 definitely seems counter-intuitive to me: why always forward even if n is negative?

I suggest changing the behavior so that negative n means even the initial search is backwards. This has the advantage that then M-- M-x iy-go-to-char would be equivalent to M-x iy-go-to-char-backward (which would then become unnecessary, if you ask me).

While I suggest changing the behavior, there might be a good reason it was designed this way, which I'd be glad to know. Even with the current behavior I would say there is a documentation bug: the documentation currently correctly states that repetitions move by one occurence instead of moving by n occurences, but it does not mention the stuff about how negative n affects the direction of search in the repetitions.

Add option to move before the match

I find the fact that iy-go-to-char jumps to after the matching character confusing, and expect it rather to end up before. Being able to customise that would be great.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.