* Re: Can I use 'C-x o o o o o' instead of C-x o C-x o C-x o C-x o C-x o?
[not found] <mailman.1779.1430218587.904.help-gnu-emacs@gnu.org>
@ 2015-04-28 17:03 ` Emanuel Berg
2015-04-28 17:48 ` Jorge A. Alfaro-Murillo
2015-04-28 18:19 ` Joe Fineman
1 sibling, 1 reply; 14+ messages in thread
From: Emanuel Berg @ 2015-04-28 17:03 UTC (permalink / raw)
To: help-gnu-emacs
<keith@cheungsfamily.org> writes:
> Scenario 1 - I split many windows. - I wish to
> switch to some other windows. - I type C-x o, C-x o,
> C-x o repeatedly until the cursor landed on the
> desired window. Is there a way to use C-x
> o o o instead?
You can't do that the normal way because then you'd
have to set up prefix keys, but they themselves would
have to be commands! - so Emacs cannot tell if it is
a prefix key (i.e. it should await more input) or if
it is a command (i.e. it should act).
However, you can do it with programming, as always,
and here's how:
The first command, which you should bind to a key,
should re-bind the keys - all keys. "o" should be
"move to the next window". All other keys should be -
let's say normal behavior is B - all other keys should
be:
a) exit this window roaming mode
b) do normal behavior B
This will make for transparency - except for the
particular key "o"! Perhaps you can insert that with
`C-u o' when you don't want to go to the next window
(only necessary in window roaming mode, of course).
This closely resembles what I did (out of someone
else's work) - this code [1] should be understandable
(I hope) and the principle is exactly the same.
Come back with more questions if need be!
> I aware that I can use C-u num C-x o, if I know the
> desired window is num step away. But there are times
> that I do not know 'num'.
OK: instead of iteration, I'd assign each window
a letter (a, b, c...) and show that in the mode bar.
Then do a function that accepts an argument which is
such a letter. Then jump to that window. I'd say this
idea is much better.
> Scenario 2 - I use the windmove package. - I bind
> the windmove-up/down/left/right to C-o i, C-o k, C-o
> j, C-o l respectively. Now, if I want to windmove to
> up-left, I type C-o i, C-o j. Is there a way to use
> C-o i j instead?
First, good bindings! `C-o i' for up etc. are great.
I love the 'ijkl' keys for 2D movements ever since
playing a monochrome Lode Runner on a Mac Plus in
the 80s.
Second, you can't do that for the same prefix/command
reason above. It would require some timeout solution
for the prefix key which would be too slow to use
anyway to be pleasant. Instead, why don't you use the
same principle as you already did and use "u", "o",
".", and "m" for combinations? E.g., "u" is up, then
left? But, here I actually think it is better to use
`C-o i', then `C-o j' and so on. I don't see any
comfort or speed disadvantage to speak of with that.
Good luck!
[1] http://user.it.uu.se/~embe8573/conf/emacs-init/caps-back.el
--
underground experts united
http://user.it.uu.se/~embe8573
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Can I use 'C-x o o o o o' instead of C-x o C-x o C-x o C-x o C-x o?
2015-04-28 17:03 ` Can I use 'C-x o o o o o' instead of C-x o C-x o C-x o C-x o C-x o? Emanuel Berg
@ 2015-04-28 17:48 ` Jorge A. Alfaro-Murillo
0 siblings, 0 replies; 14+ messages in thread
From: Jorge A. Alfaro-Murillo @ 2015-04-28 17:48 UTC (permalink / raw)
To: help-gnu-emacs
Emanuel Berg writes:
> <keith@cheungsfamily.org> writes:
>
>> Scenario 1 - I split many windows. - I wish to switch to some
>> other windows. - I type C-x o, C-x o, C-x o repeatedly until
>> the cursor landed on the desired window. Is there a way to use
>> C-x o o o instead?
>
> You can't do that the normal way because then you'd have to set
> up prefix keys, but they themselves would have to be commands! -
> so Emacs cannot tell if it is a prefix key (i.e. it should await
> more input) or if it is a command (i.e. it should act).
>
> However, you can do it with programming, as always, and here's
> how:
>
> The first command, which you should bind to a key, should
> re-bind the keys - all keys. "o" should be "move to the next
> window". All other keys should be - let's say normal behavior is
> B - all other keys should be:
>
> a) exit this window roaming mode b) do normal behavior B
That is what the function set-transient-map is used for.
>> I aware that I can use C-u num C-x o, if I know the desired
>> window is num step away. But there are times that I do not know
>> 'num'.
>
> OK: instead of iteration, I'd assign each window a letter (a, b,
> c...) and show that in the mode bar. Then do a function that
> accepts an argument which is such a letter. Then jump to that
> window. I'd say this idea is much better.
That is the idea of ace-window
(https://github.com/abo-abo/ace-window), which also is better for
Scenario 1 and even for a third scenario where you have want to
delete a particular window but do not want to move to it first.
Best,
--
Jorge.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Can I use 'C-x o o o o o' instead of C-x o C-x o C-x o C-x o C-x o?
[not found] <mailman.1779.1430218587.904.help-gnu-emacs@gnu.org>
2015-04-28 17:03 ` Can I use 'C-x o o o o o' instead of C-x o C-x o C-x o C-x o C-x o? Emanuel Berg
@ 2015-04-28 18:19 ` Joe Fineman
1 sibling, 0 replies; 14+ messages in thread
From: Joe Fineman @ 2015-04-28 18:19 UTC (permalink / raw)
To: help-gnu-emacs
張國良 <keith@cheungsfamily.org> writes:
> Scenario 1
> - I split many windows.
> - I wish to switch to some other windows.
> - I type C-x o, C-x o, C-x o repeatedly until the cursor landed on the
> desired window.
> Is there a way to use C-x o o o instead?
>
> I aware that I can use C-u num C-x o, if I know the desired window is num
> step away. But there are times that I do not know 'num'.
>
>
> Scenario 2
> - I use the windmove package.
> - I bind the windmove-up/down/left/right to C-o i, C-o k, C-o j, C-o l
> respectively. Now, if I want to windmove to up-left, I type C-o i, C-o j.
> Is there a way to use C-o i j instead?
I long ago put the following in my .emacs:
(defun goto-next-window ()
"Go to the next window after saving the current buffer."
(interactive)
(if (buffer-file-name) (save-buffer))
(other-window 1))
(defun goto-previous-window ()
"Go to the previous window after saving the current buffer."
(interactive)
(if (buffer-file-name) (save-buffer))
(other-window -1))
(global-set-key (kbd "C-<prior>") 'goto-previous-window)
(global-set-key (kbd "C-<next>") 'goto-next-window)
--
--- Joe Fineman joe_f@verizon.net
||: The higher the monkey climbs, the more he shows his rear. :||
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Can I use 'C-x o o o o o' instead of C-x o C-x o C-x o C-x o C-x o?
2015-04-28 10:56 張國良
@ 2015-04-28 13:47 ` Tassilo Horn
2015-04-28 13:49 ` Yuri D'Elia
` (7 subsequent siblings)
8 siblings, 0 replies; 14+ messages in thread
From: Tassilo Horn @ 2015-04-28 13:47 UTC (permalink / raw)
To: 張國良; +Cc: help-gnu-emacs@gnu.org
張國良 <keith@cheungsfamily.org> writes:
Hi!
I don't think there is (nor can there be) a generic way to do that.
> Scenario 1
> - I split many windows.
> - I wish to switch to some other windows.
> - I type C-x o, C-x o, C-x o repeatedly until the cursor landed on the
> desired window.
> Is there a way to use C-x o o o instead?
What if you want to switch to the other window and insert some "o"s
there? With your suggested approach, you cannot do that.
> I aware that I can use C-u num C-x o, if I know the desired window is num
> step away. But there are times that I do not know 'num'.
>
> Scenario 2
> - I use the windmove package.
> - I bind the windmove-up/down/left/right to C-o i, C-o k, C-o j, C-o l
> respectively. Now, if I want to windmove to up-left, I type C-o i, C-o j.
> Is there a way to use C-o i j instead?
If you wanted to, you could define some `windmove-minor-mode' with a
keymap binding i, k, j, and l to the respective windmove commands, and a
binding for return and/or escape which deactivates this mode. Then you
could bind C-o to `windmove-minor-mode'. Using that, you could do
C-o i j j l RET
where the RET would signal that you've finished moving around.
Alternatively, you could remap `self-insert-command' to deactivating
that mode. In this case, any key you press except for i/j/k/l would
exit this "movement mode".
HTH,
Tassilo
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Can I use 'C-x o o o o o' instead of C-x o C-x o C-x o C-x o C-x o?
2015-04-28 10:56 張國良
2015-04-28 13:47 ` Tassilo Horn
@ 2015-04-28 13:49 ` Yuri D'Elia
2015-04-28 13:50 ` Jorge A. Alfaro-Murillo
` (6 subsequent siblings)
8 siblings, 0 replies; 14+ messages in thread
From: Yuri D'Elia @ 2015-04-28 13:49 UTC (permalink / raw)
To: help-gnu-emacs
On 04/28/2015 12:56 PM, 張國良 wrote:
> Hi all,
>
> Scenario 1
> - I split many windows.
> - I wish to switch to some other windows.
> - I type C-x o, C-x o, C-x o repeatedly until the cursor landed on the
> desired window.
> Is there a way to use C-x o o o instead?
>
> I aware that I can use C-u num C-x o, if I know the desired window is num
> step away. But there are times that I do not know 'num'.
I started to use window-numbering-mode (window-numbering from melpa) and
never looked back.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Can I use 'C-x o o o o o' instead of C-x o C-x o C-x o C-x o C-x o?
2015-04-28 10:56 張國良
2015-04-28 13:47 ` Tassilo Horn
2015-04-28 13:49 ` Yuri D'Elia
@ 2015-04-28 13:50 ` Jorge A. Alfaro-Murillo
2015-04-28 14:22 ` Jorge A. Alfaro-Murillo
2015-04-28 14:07 ` Drew Adams
` (5 subsequent siblings)
8 siblings, 1 reply; 14+ messages in thread
From: Jorge A. Alfaro-Murillo @ 2015-04-28 13:50 UTC (permalink / raw)
To: help-gnu-emacs
張國良 writes:
> Scenario 1 - I split many windows. - I wish to switch to some
> other windows. - I type C-x o, C-x o, C-x o repeatedly until
> the cursor landed on the desired window. Is there a way to use
> C-x o o o instead?
>
> I aware that I can use C-u num C-x o, if I know the desired
> window is num step away. But there are times that I do not know
> 'num'.
>
> Scenario 2 - I use the windmove package. - I bind the
> windmove-up/down/left/right to C-o i, C-o k, C-o j, C-o l
> respectively. Now, if I want to windmove to up-left, I type C-o
> i, C-o j. Is there a way to use C-o i j instead?
You could try something like:
#+BEGIN_SRC emacs-lisp
(defvar your-extended-keymap (make-sparse-keymap))
(define-key your-extended-keymap (kbd "o") 'other-window)
(advice-add 'other-window
:after
(lambda () (set-transient-map
your-extended-keymap)))
#+END_SRC
>
> Many thanks.
>
Best,
--
Jorge.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Can I use 'C-x o o o o o' instead of C-x o C-x o C-x o C-x o C-x o?
2015-04-28 13:50 ` Jorge A. Alfaro-Murillo
@ 2015-04-28 14:22 ` Jorge A. Alfaro-Murillo
0 siblings, 0 replies; 14+ messages in thread
From: Jorge A. Alfaro-Murillo @ 2015-04-28 14:22 UTC (permalink / raw)
To: help-gnu-emacs
Jorge A. Alfaro-Murillo writes:
> 張國良 writes:
>
>> Scenario 1 - I split many windows. - I wish to switch to some
>> other windows. - I type C-x o, C-x o, C-x o repeatedly until
>> the cursor landed on the desired window. Is there a way to use
>> C-x o o o instead? I aware that I can use C-u num C-x o, if
>> I know the desired window is num step away. But there are
>> times that I do not know 'num'.
>>
>> Scenario 2 - I use the windmove package. - I bind the
>> windmove-up/down/left/right to C-o i, C-o k, C-o j, C-o l
>> respectively. Now, if I want to windmove to up-left, I type
>> C-o i, C-o j. Is there a way to use C-o i j instead?
>
> You could try something like:
>
> #+BEGIN_SRC emacs-lisp
> (defvar your-extended-keymap (make-sparse-keymap)) (define-key
> your-extended-keymap (kbd "o") 'other-window) (advice-add
> 'other-window
> :after (lambda () (set-transient-map
> your-extended-keymap)))
> #+END_SRC
Sorry, I hit send before finishing, this works:
#+BEGIN_SRC emacs-lisp
(defvar your-extended-keymap (make-sparse-keymap))
(define-key your-extended-keymap (kbd "o") 'your-other-window)
(defun your-other-window ()
(interactive)
(other-window 1)
(set-transient-map your-extended-keymap))
(global-set-key (kbd "C-x o") 'your-other-window)
#+END_SRC
But as Tassilo said, you probably do not want this. Check
ace-window (https://github.com/abo-abo/ace-window) which solves
both scenarios very elegantly.
Best,
--
Jorge.
^ permalink raw reply [flat|nested] 14+ messages in thread
* RE: Can I use 'C-x o o o o o' instead of C-x o C-x o C-x o C-x o C-x o?
2015-04-28 10:56 張國良
` (2 preceding siblings ...)
2015-04-28 13:50 ` Jorge A. Alfaro-Murillo
@ 2015-04-28 14:07 ` Drew Adams
2015-04-28 14:07 ` Phillip Lord
` (4 subsequent siblings)
8 siblings, 0 replies; 14+ messages in thread
From: Drew Adams @ 2015-04-28 14:07 UTC (permalink / raw)
To: 張國良, help-gnu-emacs
> Scenario 1
> - I split many windows.
> - I wish to switch to some other windows.
> - I type C-x o, C-x o, C-x o repeatedly until the cursor landed on
> the desired window. Is there a way to use C-x o o o instead?
Yes. Using function `repeat-command', this command, like lots of
others, is made "repeatable": You can bind the repeatable command
to a key sequence that includes a prefix key and then just repeat
the last key: `C-x o o o o o...'.
A prefix arg you give to the command initially is passed to each
subsequent consecutive call. So for example, `C-2 C-x o o o ...'
cycles through every other window.
(defun other-window-repeat (count)
"Repeatable `other-window'."
(interactive "p")
(require 'repeat)
(repeat-command 'other-window))
(global-set-key "\C-xo" 'other-window-repeat)
Here is `repeat-command', from `misc-cmds.el'.
http://www.emacswiki.org/emacs/download/misc-cmds.el
(defun repeat-command (command)
"Repeat COMMAND."
(let ((repeat-message-function 'ignore))
(setq last-repeatable-command command)
(repeat nil)))
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Can I use 'C-x o o o o o' instead of C-x o C-x o C-x o C-x o C-x o?
2015-04-28 10:56 張國良
` (3 preceding siblings ...)
2015-04-28 14:07 ` Drew Adams
@ 2015-04-28 14:07 ` Phillip Lord
2015-04-28 14:23 ` Tak Kunihiro
` (3 subsequent siblings)
8 siblings, 0 replies; 14+ messages in thread
From: Phillip Lord @ 2015-04-28 14:07 UTC (permalink / raw)
To: 張國良; +Cc: help-gnu-emacs@gnu.org
張國良 <keith@cheungsfamily.org> writes:
> Scenario 1
> - I split many windows.
> - I wish to switch to some other windows.
> - I type C-x o, C-x o, C-x o repeatedly until the cursor landed on the
> desired window.
> Is there a way to use C-x o o o instead?
>
> I aware that I can use C-u num C-x o, if I know the desired window is num
> step away. But there are times that I do not know 'num'.
I think hydra does effectively this.
https://github.com/abo-abo/hydra
It allows you to define a set of linked commands, though, rather than
working over already existing commands.
Phil
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Can I use 'C-x o o o o o' instead of C-x o C-x o C-x o C-x o C-x o?
2015-04-28 10:56 張國良
` (4 preceding siblings ...)
2015-04-28 14:07 ` Phillip Lord
@ 2015-04-28 14:23 ` Tak Kunihiro
2015-04-28 19:04 ` Robert Thorpe
` (2 subsequent siblings)
8 siblings, 0 replies; 14+ messages in thread
From: Tak Kunihiro @ 2015-04-28 14:23 UTC (permalink / raw)
To: keith, help-gnu-emacs; +Cc: tkk
Use smartrep. I use it 1,000 times a day.
https://github.com/myuhe/smartrep.el
Side effect is you cannot insert `o' soon after (other-window).
Because of this side effect, this is not adequate for default
behavior.
(require 'smartrep)
(smartrep-define-key global-map "C-x"
'(("o" . 'other-window)
("O" . 'other-frame)
("^" . 'enlarge-window)
("_" . 'shrink-window)
("{" . 'shrink-window-horizontally)
("}" . 'enlarge-window-horizontally)))
> - I split many windows.
> - I wish to switch to some other windows.
> - I type C-x o, C-x o, C-x o repeatedly until the cursor landed on the
> desired window.
> Is there a way to use C-x o o o instead?
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Can I use 'C-x o o o o o' instead of C-x o C-x o C-x o C-x o C-x o?
2015-04-28 10:56 張國良
` (5 preceding siblings ...)
2015-04-28 14:23 ` Tak Kunihiro
@ 2015-04-28 19:04 ` Robert Thorpe
2015-04-30 9:56 ` 張國良
[not found] ` <mailman.1786.1430228989.904.help-gnu-emacs@gnu.org>
8 siblings, 0 replies; 14+ messages in thread
From: Robert Thorpe @ 2015-04-28 19:04 UTC (permalink / raw)
To: 張國良; +Cc: help-gnu-emacs
> Scenario 1
> - I split many windows.
> - I wish to switch to some other windows.
> - I type C-x o, C-x o, C-x o repeatedly until the cursor landed on the
> desired window.
> Is there a way to use C-x o o o instead?
Instead of "C-x o" I have other-window bound to C-1. I hold down ctrl with
my palm and then press 1 until I reach the right window.
I find that very few commands need a prefix argument of 1. When I
encounter one of those commands I use M-1 instead.
BR,
Robert Thorpe
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Can I use 'C-x o o o o o' instead of C-x o C-x o C-x o C-x o C-x o?
2015-04-28 10:56 張國良
` (6 preceding siblings ...)
2015-04-28 19:04 ` Robert Thorpe
@ 2015-04-30 9:56 ` 張國良
[not found] ` <mailman.1786.1430228989.904.help-gnu-emacs@gnu.org>
8 siblings, 0 replies; 14+ messages in thread
From: 張國良 @ 2015-04-30 9:56 UTC (permalink / raw)
To: help-gnu-emacs@gnu.org
Thanks all for the ideas.
I end up use hydra and ace window.
Here is my config if you are interested.
> ** Hydra the windmove keys & move spliter
>
> #+BEGIN_SRC emacs-lisp
>
> (require 'hydra)
>
> (defhydra hydra-windmove (global-map "C-o")
>
> "windmove with ijkl"
>
> ("i" windmove-up "up")
>
> ("j" windmove-left "left")
>
> ("k" windmove-down "down")
>
> ("l" windmove-right "right")
>
> ("n" other-window "next")
>
> ("p" (other-window -1) "prev")
>
> ("[" hydra-move-splitter-left)
>
> ("." hydra-move-splitter-down)
>
> ("," hydra-move-splitter-up)
>
> ("]" hydra-move-splitter-right)
>
> )
>
>
>> (defun hydra-move-splitter-left (arg)
>
> "Move window splitter left."
>
> (interactive "p")
>
> (if (let ((windmove-wrap-around))
>
> (windmove-find-other-window 'right))
>
> (shrink-window-horizontally arg)
>
> (enlarge-window-horizontally arg)))
>
>
>> (defun hydra-move-splitter-right (arg)
>
> "Move window splitter right."
>
> (interactive "p")
>
> (if (let ((windmove-wrap-around))
>
> (windmove-find-other-window 'right))
>
> (enlarge-window-horizontally arg)
>
> (shrink-window-horizontally arg)))
>
>
>> (defun hydra-move-splitter-up (arg)
>
> "Move window splitter up."
>
> (interactive "p")
>
> (if (let ((windmove-wrap-around))
>
> (windmove-find-other-window 'up))
>
> (enlarge-window arg)
>
> (shrink-window arg)))
>
>
>> (defun hydra-move-splitter-down (arg)
>
> "Move window splitter down."
>
> (interactive "p")
>
> (if (let ((windmove-wrap-around))
>
> (windmove-find-other-window 'up))
>
> (shrink-window arg)
>
> (enlarge-window arg)))
>
> #+END_SRC
>
>
>> ** Ace window (switch to window with number)
>
> #+BEGIN_SRC emacs-lisp
>
> (require 'ace-window)
>
> (global-set-key (kbd "M-p") 'ace-window)
>
> #+END_SRC
>
>
>>
2015-04-28 18:56 GMT+08:00 張國良 <keith@cheungsfamily.org>:
> Hi all,
>
> Scenario 1
> - I split many windows.
> - I wish to switch to some other windows.
> - I type C-x o, C-x o, C-x o repeatedly until the cursor landed on the
> desired window.
> Is there a way to use C-x o o o instead?
>
> I aware that I can use C-u num C-x o, if I know the desired window is num
> step away. But there are times that I do not know 'num'.
>
>
> Scenario 2
> - I use the windmove package.
> - I bind the windmove-up/down/left/right to C-o i, C-o k, C-o j, C-o l
> respectively. Now, if I want to windmove to up-left, I type C-o i, C-o j.
> Is there a way to use C-o i j instead?
>
>
> Many thanks.
>
>
>
^ permalink raw reply [flat|nested] 14+ messages in thread
[parent not found: <mailman.1786.1430228989.904.help-gnu-emacs@gnu.org>]