emacs scroll other window up - emacs

In Emacs we can scroll inactive window using certain commands
But not all details are listed in the manual.
C-M-v can scroll down the other window
my intention is to scroll up the other window, how could I do that ?

Try C-M-S-v, which is scroll-other-window-down.
You can find such key bindings by doing C-h b (describe-bindings) which populates the *Help* buffer with a list of all the key bindings and associated commands for the current buffer. A quick search through that for scroll-other showed the binding you mentioned, as well as the one I listed.

On many terminals you can do M-PageUp and M-PageDn to scroll the other window. It's nice if you're already used to using PageUp/PageDn for scrolling.

You can alternatively give a negative argument to C-M-v.
Negative arguments can be given with almost any modifier combination.
In that case you can type C-M-- C-M-v.

I use this (everyday) :
(define-key global-map [(meta up)] '(lambda() (interactive) (scroll-other-window -1)))
(define-key global-map [(meta down)] '(lambda() (interactive) (scroll-other-window 1)))

scroll down,
(scroll-other-window)
scroll up,
(scroll-other-window '-)
scroll-other-window is the native C API of Emacs, so it should work out of the box. Check its documentation.
Feel free to assign hot key for them

You could do C-u - C-M-v (i.e. scroll-other-window with ARG -) if C-M-S-v (i.e. scroll-other-window-down) does not work for you, as could happen when using Emacs in a terminal.
Excerpt from C-h f scroll-other-window:
Negative ARG means scroll downward. If ARG is the atom '-', scroll downward by nearly full screen.

Related

completing-read-default auto-focus candidate window

How to automatically set focus to window with displayed candidates (after tab punch) in default emacs read with autocompletion?
I can not use IDO nor other autocompletion systems in my case because I need to browse through 80k+ candidates, and only autocompletion system which can handle this is the default one.
I will be glad for any useful pointers.
EDIT
After some research, I get to work following imperfect solution:
(define-key minibuffer-local-completion-map
(kbd "<tab>")
(lambda ()
(interactive)
(call-interactively 'minibuffer-complete)
(call-interactively 'switch-to-completions)))
(define-key completion-list-mode-map
(kbd "C-f")
'isearch-forward)
Only problem is, after I enter completing-read-default, I must first hit TAB to open window with candidates (with newly added autofocus). But I want it to open window with candidates immediately without need to hit TAB. How to do it? I tried to call minibuffer-complete after call to completing-read-default but it doesnt opened window with candidates, only standard minibuffer prompt.
After some pain, I finally found solution
(defun custom/default-completing-read (question candidates)
(run-at-time "0.5" nil
(lambda ()
(minibuffer-complete)
(switch-to-completions)
(isearch-forward)))
(completing-read-default question candidates))
After call, it invokes default (written in C) completion system which can handle tons and tons of candidates without problems with automatic jump into candidate selection with isearch-forward enabled.
Hope it will help someone in future ...

Emacs move around split windows in a specified direction?

In Terminal Emacs (no mouse), I'm using split windows to work with multiple buffers at the same time. I'm finding moving between the split windows much more painful than how I do it in Vim. Reading the documentation it looks like I'm doing it correctly (C-x o), but that just cycles around the windows in a clockwise direction. If I move to an adjacent window to make a quick edit, I need to hit C-x o a few times before I'm back where I was. Sometimes I accidentally press it too many times in a hurry and have to cycle all the way back through the windows again.
Far from install yet-another-external-package, is there any way I can just either move directly to a window (by, say, a number), or at least cycle around the windows in the opposite direction?
In Vim C-w C-w is like C-x o in Emacs, but there's also C-w ARROW to move in a specified direction... something like that? :)
Add this to your init file:
(windmove-default-keybindings)
Then you can use SHIFT+arrow to move to the next adjacent window in the specified direction.
You can specify a different modifier if you prefer, by passing an argument (defaults to 'shift).
Or just bind whatever you like to these functions:
windmove-up
windmove-down
windmove-left
windmove-right
You can also add FrameMove to the mix, to make this work transparently across multiple frames.
For numbered window navigation, there's switch-window.el.
Add this to your init file (e.g. ~/.emacs):
(windmove-default-keybindings)
Then do SHIFT+arrow to move to the window in that direction.
You can give a prefix argument to C-x o like this C-u -1 C-x o. This way you can go any number of windows forward or backward. Personally I think it's easier to create a special key for moving back one window. I have this in my .emacs:
(defun other-window-backward ()
"Goto previous window"
(interactive)
(other-window -1))
(global-set-key (kbd "\C-x p") 'other-window-backward)
I use the following to navigate to the next (same as C-x o), previous, first, and last window:
(defun my-previous-window ()
"Previous window"
(interactive)
(other-window -1))
(global-set-key "\C-xp" 'my-previous-window)
(global-set-key "\C-xn" 'other-window)
(defun my-select-first-window ()
(interactive)
(select-window (frame-first-window)))
(defun my-select-last-window ()
(interactive)
(select-window (previous-window (frame-first-window))))
(global-set-key "\C-x<" 'my-select-first-window)
(global-set-key "\C-x>" 'my-select-last-window)
Use window-jump, e.g.:
;; C-x <direction> to switch windows
(use-package window-jump
:bind (("C-x <up>" . window-jump-up)
("C-x <down>" . window-jump-down)
("C-x <left>" . window-jump-left)
("C-x <right>" . window-jump-right)))
For help with use-package, see https://github.com/jwiegley/use-package/blob/master/README.md.
For the sake of completion, there is window-numbering and ace-window too
I wrote an elisp module a while back to expand on windmove to make it a bit more useful: http://samograd.ca/stumpwm.el. You can bind stumpwm-move-window-[left/right/up/down] to whatever keys you want and the windows will move in the correct direction, even into another another frame (tested with 2 frames). There's also an stumpwm-interactive-resize-window for handy interactive window resizing using C-n/C-p/C-f/C-b with Return to end resizing.

In Emacs split windows, how to browse the other window?

I used C-x 3 to split to left and right windows. The cursor is in left window and I can use C-n, C-p to move the cursor. How can I stay in the left window and move the code in right window up and down?
I have done this before but I lost all my emacs files. So I cannot figure it out right now. Thanks.
I've googled for the answer, Re: How to scroll other window backwards? C-M-v does forwards
Still, use scroll-other-window function and add parameters to it. Below are the details:
(defun scroll-other-window-up-line ()
"Scroll the other window one line up."
(interactive)
(scroll-other-window -1))
(defun scroll-other-window-down-line ()
"Scroll the other window one line down."
(interactive)
(scroll-other-window 1))
(global-set-key (kbd "M-p") 'scroll-other-window-up-line)
(global-set-key (kbd "M-n") 'scroll-other-window-down-line)
Hope it can help.
scroll-other-window is your friend, bound to C-M-v by default.

Is there a better way to switch between multiple windows in emacs gdb besides C-x-o?

I'm using gdb-many-windows, which contains five windows to switch between. Is there a shortcut I can use to get to a specific window?
You probably already know that C-x o gets you to the next window. You can extend this to go to any arbitrary window with C-u <windowoffset> C-x o.
So, you can use C-u 2 C-x o to switch to the second window ahead of your current one.
This wraps around the window list (so in your case of 5 windows you could do C-u 4 c-x o to go back one.
You can also use negative numbers as well to go backwards.
Lastly, it takes a bit more setup, but Thomas's suggestion to use WindMove is very useful. It wasn't configured by default for me to any useful key binding. I add the following snippet to my (mac) .emacs file, whch lets me switch windows via control-arrow (you will need to reload .emacs by starting up or via 'M-x load-file')
(global-set-key (kbd "M-[ 5 d") 'windmove-left)
(global-set-key (kbd "M-[ 5 c") 'windmove-right)
(global-set-key (kbd "M-[ 5 a") 'windmove-up)
(global-set-key (kbd "M-[ 5 b") 'windmove-down)
Some people find WindMove more convenient than C-x o. It allows you to navigate between windows using Shift + arrow keys.
Possibly useful links:
http://www.emacswiki.org/emacs/WindowNumberingMode
http://www.emacswiki.org/emacs/NumberedWindows
Edit: If you decide to use WindowNumberingMode (that's what I use) you might find it useful to pin buffers to windows (so, for instance, Meta-1 switches to the buffer you expect it to switch to, not just the first window). One way of pinning is described in Pin Emacs buffers to windows (for cscope).
Window switching is so important in emacs, I have these settings.(Still feel these are not good enough)..
may help someone else..
(global-set-key "\M-t" 'other-window) ;; was transpose words
(global-set-key (kbd "C-x O") (lambda () (interactive) (other-window -1))) ;; back one
(global-set-key (kbd "C-x C-o") (lambda () (interactive) (other-window 2))) ;; forward t
I use switch-window.el.
You can choose a window by visual way with 'switch-window'.
Image of using switch-window

emacs zoom in/zoom out

Is there a way to zoom in and out (dynamically change the font size, quite smoothly) on emacs?
Try C-x C-+ and C-x C--; that is, Control-x Control-Minus/Control-Plus.
After one combination (C-x C-+ or C-x C--), successives + or - increase or decrease the text scale without typing C-x C- again.
Addition by sawa
I looked up the function that was assigned to the keys mentioned, and found out that they are text-scale-increase and text-scale-decrease. I added the following to my configuration file so that I can do Ctrl+Scroll to zoom in/out. It is useful.
(global-set-key [C-mouse-4] 'text-scale-increase)
(global-set-key [C-mouse-5] 'text-scale-decrease)
The -very nice- answer of user173973 is binding the functions to non-generic mouse events. That is to say that for example on my windows system, the binding command is not valid.
To use it on windows (or probably anywhere) you can use these generic bindings :
(global-set-key [C-mouse-wheel-up-event] 'text-scale-increase)
(global-set-key [C-mouse-wheel-down-event] 'text-scale-decrease)
This config worked for me:
(global-set-key [C-wheel-up] 'text-scale-increase)
(global-set-key [C-wheel-down] 'text-scale-decrease)
In addition to sawa's accepted response, I prefer to use the keyboard exclusively. Here are some additions to my init.el file that meet that preference similarly to the short cuts found on Windows/MacOS desktops:
;; enable shortcuts (both keyboard and mouse) for zoom-in/zoom-out
(global-set-key [C-mouse-4] 'text-scale-increase)
(global-set-key [C-mouse-5] 'text-scale-decrease)
(global-set-key [?\C-\+] 'text-scale-increase)
(global-set-key [?\C-\-] 'text-scale-decrease)
All windows
You'll often want to change your font size because you're showing something to others. Then you likely want all windows to zoom in (including mode-line). For this, default-text-scale is great.
I bind it as such:
(key-seq-define-global "q-" 'default-text-scale-decrease)
(key-seq-define-global "q+" 'default-text-scale-increase)
(global-set-key (kbd "C-M-_") 'default-text-scale-decrease)
(global-set-key (kbd "C-M-+") 'default-text-scale-increase)
Quick single window, and back
For a really quick heavy (16x) zoom-in, you can use: C-u C-u C-x C-+
For going to single-window mode, say for a org presentation: C-x 1
Then you can undo the single-window and return to whatever layout you had before with winner-undo: C-c <left>
Whole desktop
Relatedly, for sharing over a video call, it might be easiest to just change (lower) your desktop resolution. On linux, I pop up arandr for this before starting a sharing session.