Defining Control-Shift-* Emacs keyboard shortcuts - emacs

I'm trying to define the following two keyboard shortcuts to move between windows in Emacs:
C-shift-n: Move to the next window
C-shift-b: Move to the previous window
I thought the following will do it but it doesn't.
(defun select-next-window ()
"Switch to the next window"
(interactive)
(select-window (next-window)))
(defun select-previous-window ()
"Switch to the previous window"
(interactive)
(select-window (previous-window)))
(global-set-key (kbd "C-<S-n>") 'select-next-window)
(global-set-key (kbd "C-<S-p>") 'select-previous-window)
The problem seems to be with the last two lines that define the actual keyboard shortcuts to the functions that switch the windows (if I use simpler keyboard shortcuts instead of Control-Shift-* it works).
So, how do I use kbd to define Control-Shift-n and Control-Shift-p?

Assuming you never use caps lock, here's a super simple solution:
(global-set-key (kbd "C-N") 'select-next-window)
or
(global-set-key (kbd "C-<S-N>") 'select-next-window)
The problem is that when you hit shift you're sending capital N.

Related

How to enter minibuffer for editing in Emacs?

When running certain commands, the mini-buffer asks input strings, (e.g. the C-M-s).
Sometimes I need to enter complex strings into minibuffer. Therefore, I need to use movement commands such as C-f, C-b, C-a, etc. However, these does not work when I am entering string inside command C-M-s.
So, what is the general command / key-bindings for me to focus point in mini-buffer for extended movement support?
Edit:
I just discovered that M-e will work for searching commands. But I am not sure whether this command is the general command to "switch from buffer to minibuffer for dedicated editing"
Yes, M-e is what you are looking for, if you want to edit the search string. It lets you perform general editing on it. Just hit C-s or C-M-s again when you are ready to search for the edited string.
However, M-e is only for editing the search string. If you instead want to interrupt isearch to do some editing somewhere, then just end isearch to do that, and then resume isearch when done editing, by using C-s or C-M-s again.
I have been happy using these and I bind them to the function button and arrow keys on my Mac keyboard. I frequently block and copy text and move in and out of the mini-buffer. The following example frees up some of the keymap assignments in the minibuffer-local-map and minibuffer-local-completion-map (i.e., by setting them to nil) so that I can use my own custom keyboard shortcuts to enter and exit the mini-buffer.
From inside the mini-buffer, you can use C-h k and then the type the keyboard shortcut to see what function is bound.
When I switch in and out of the mini-buffer window, I use a custom function that changes the mode-line color, and mini-buffer prompt color, and default color inside the mini-buffer, but that is beyond the scope of your question. [I just add the name of my mini-buffer color change function at the tail end of the following four functions -- i.e., after the if / then statements.]
(defun lawlist-windmove-right ()
(interactive)
(if (window-in-direction 'right)
(select-window (window-in-direction 'right))
(other-window 1)))
(defun lawlist-windmove-left ()
(interactive)
(if (window-in-direction 'left)
(select-window (window-in-direction 'left))
(other-window -1)))
(defun lawlist-windmove-up ()
(interactive)
(if (window-in-direction 'above)
(select-window (window-in-direction 'above))
(other-window 1)))
(defun lawlist-windmove-down ()
(interactive)
(if (window-in-direction 'below)
(select-window (window-in-direction 'below))
(other-window -1)))
(define-key minibuffer-local-map [prior] nil)
(define-key minibuffer-local-map [next] nil)
(define-key minibuffer-local-map [home] nil)
(define-key minibuffer-local-map [end] nil)
(define-key minibuffer-local-completion-map [prior] nil)
(define-key minibuffer-local-completion-map [next] nil)
(define-key minibuffer-local-completion-map [home] nil)
(define-key minibuffer-local-completion-map [end] nil)
(global-set-key (kbd "<end>") 'lawlist-windmove-right)
(global-set-key (kbd "<home>") 'lawlist-windmove-left)
(global-set-key (kbd "<prior>") 'lawlist-windmove-up)
(global-set-key (kbd "<next>") 'lawlist-windmove-down)

emacs, flyspell, deactivate "C-." key binding

I have this little problem, I have some key bindings like so C-. C-x or C-. C-m. After I activate the flyspell-mode, I cannot use these commands. In my .emacs file I have the next 2 lines before
(global-unset-key (kbd "C-."))
(define-key (current-global-map) (kbd "C-.") nil)
(global-set-key (kbd "C-. C-l") 'global-linum-mode)
Then, my C-. C-l works, but it does not when the flyspell-mode is activated. The command bound to C-. is flyspell-auto-correct-word. I tried to deactivate it as follows:
;; first try
(defun flyspell-auto-correct-word-disable() (define-key (current-local-map) (kbd "C-.") nil))
(add-hook 'flyspell-mode-hook 'flyspell-auto-correct-word-disable)
;; second try
(define-key (current-global-map) [remap flyspell-auto-correct-word] nil)
None of the tries work, what can I do? I tried in Emacs 23 and 24 and I have the same issue.
What about:
(eval-after-load "flyspell"
'(define-key flyspell-mode-map (kbd "C-.") nil))
Your first solution is almost correct, but you have to remember that the current local map is set up by the major mode, not minor modes. The best option you have it to directly access flyspell-mode-map and modify it (another option would be to find it in minor-mode-map-alist but I think it would be needlessly complicated).
Also, I prefer putting such mode-specific settings within eval-after-load (which means they will be evaluated once) rather than in a hook (in which case the settings are evaluated multiple times: each time one buffer activates flyspell-mode). But this is a matter of preference and either way is fine.

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

elisp how to check if Shift key is pressed

I need to check if Shift key is pressed.
More exactly I would like to set dired switches depending on whether Shift is pressed.
(defadvice find-file-noselect (around find-file-noselect-set-switches activate)
(let ((switches dired-listing-switches))
;; check if shift is pressed and set or not an "R" switch
(setq dired-listing-switches "-lhRA")
ad-do-it
(setq dired-listing-switches switches)))
Of course, I can have different shortcuts for different dired switches, but I would like to change my switches dynamically during choosing a directory for dired.
Duplicate question (ignoring the 'Windows' part of the other one).
Can I send a keypress to Windows from Emacs?
The best you can do (is as you mention) have different shortcuts. They can be differentiated by capitalization... for example
(global-set-key (kbd "C-x C-D") 'dired-with-some-switches)
(global-set-key (kbd "C-x C-d") 'dired-with-other-switches)

touchpad horizontal scrolling in emacs

app on Mac OS X on a MacBook. Most applications on the computer allow me to scroll both vertically and horizontally with a two-finger drag on the trackpad. I would like to use this ability to position the cursor in emacs.
Adding the following lines to .emacs allows me to move the cursor vertically:
(global-set-key [wheel-up] 'previous-line)
(global-set-key [wheel-down] 'next-line)
I don't know of an equivalent setting for wheel-left or wheel-right. Can anyone help?
Put this in your .emacs-file:
;; Turn on horizontal scrolling with mouse wheel
(global-set-key (kbd "<mouse-6>") 'scroll-right)
(global-set-key (kbd "<mouse-7>") 'scroll-left)
When you first use it, emacs will ask you if you want to activate the restricted command scroll-left. That's just because some users find it confusing at first.
this slightly simpler version works for me:
(global-set-key [wheel-right] 'scroll-left)
(global-set-key [wheel-left] 'scroll-right)
or for osx reversed scroll directions:
(global-set-key [wheel-right] 'scroll-left)
(global-set-key [wheel-left] 'scroll-right)
(global-set-key (kbd "<mouse-7>")
(lambda () (interactive) (message "WHEEEEEL")))
That worked for me. Try C-h c and then scroll the mouse the way you intend to to see what event is triggered. It will tell you in the echo area.
In version 26.2 I can set these variables from the mouse customize group:
'(mouse-wheel-flip-direction t) ;; correct left-right scroll direction for OS X
'(mouse-wheel-tilt-scroll t) ;; enable left-right scroll from trackpad
In emacs 25.1 check out the *Messages* buffer when you swipe left and right on the trackpad. By the looks of it the key bindings are wheel-right and wheel-left with double and triple variants.
For example:
(global-set-key (kbd "<triple-wheel-right>")
(lambda () (interactive) (message "wheeling right")))
(global-set-key (kbd "<triple-wheel-left>")
(lambda () (interactive) (message "wheeling left")))
For me these values are not reversed in macOS