I copied this from somewhere, and it works well for scrolling one line at a time.
(setq mouse-wheel-scroll-amount '(1 ((shift) . 1))) ;; one line at a time
However, I don't understand the meaning of '(1 ((shift) . 1) here.
What does the shift do?
As with any variable in Emacs, use C-hv mouse-wheel-scroll-amount to learn about it.
In this instance I see:
mouse-wheel-scroll-amount is a variable defined in ‘mwheel.el’.
Its value is (5 ((shift) . 1) ((control)))
Documentation:
Amount to scroll windows by when spinning the mouse wheel.
This is an alist mapping the modifier key to the amount to scroll when
the wheel is moved with the modifier key depressed.
Elements of the list have the form (MODIFIERS . AMOUNT) or just AMOUNT if
MODIFIERS is nil.
AMOUNT should be the number of lines to scroll, or nil for near full
screen. It can also be a floating point number, specifying the fraction of
a full screen to scroll. A near full screen is ‘next-screen-context-lines’
less than a full screen.
Which is slightly technical, but is telling me that Emacs will scroll 5 lines at a time when I use the mouse wheel by default; but just 1 line at a time when I am holding shift; and if I am holding ctrl then it will scroll something close to a full screen at a time -- as ((control)) is the same thing as ((control) . nil).
The behaviour of:
(setq mouse-wheel-scroll-amount '(1 ((shift) . 1)))
is therefore equivalent to simply
(setq mouse-wheel-scroll-amount '(1))
as in the latter case, there are no overrides for modifier keys.
Related
In emacs, how to jump to the variable definition when the cursor is sitting on the variable itself.
like,
((let x 1)
(message x))
The cursor is in second line on the variable, x. When the shortcut key is pressed, the emacs point must be moved to the first line middle.
I am using the mac emacs from http://emacsformacosx.com/, and I need to click the maximized icon when I start my emacs.
How can I set the maximized emacs window as default?
start emacs like this
emacs -mm
Ryan McGeary's maxframe.el works well for me on both Aquamacs and Emacs.app. I found it through EmacsWiki: http://www.emacswiki.org/emacs/FullScreen . That page talks about a patched version which is now a 404 page, but the original one at https://github.com/rmm5t/maxframe.el seems to work fine.
Here is a function written and used by me. When you succesivelly press F11, emacs switches in 4 modes:
(defun switch-fullscreen nil
(interactive)
(let* ((modes '(nil fullboth fullwidth fullheight))
(cm (cdr (assoc 'fullscreen (frame-parameters) ) ) )
(next (cadr (member cm modes) ) ) )
(modify-frame-parameters
(selected-frame)
(list (cons 'fullscreen next)))))
(define-key global-map [f11] 'switch-fullscreen)
The short answer is to add the following to your custom-set-variables:-
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
...
'(initial-frame-alist (quote ((fullscreen . maximized))))
...
)
Given below is what I wanted as a solution to the same problem. TL;DR.
I face the same problem but in all applications and not just in Emacs. To this end, I have globally bound the shortcut key cmd-m on my Mac to the Zoom menu option which is usually the menu option for the green maximize button. Emacs however doesn't provide the Zoom menu option which is usually under the Window menu item. So I ended up with the following.
I just coded up the following last night.
;; This defines cmd-m to do the same as clicking the green titlebar button
;; usually meant for the "Window -> Zoom" menu option in Mac apps
(defun zoom () "zoom, same as clicking the green titlebar button in Mac app windows"
(interactive)
(set-frame-parameter
nil 'fullscreen
(pcase (frame-parameter nil 'fullscreen)
(`nil 'fullheight)
(`fullheight 'maximized)
(`fullboth (ding) 'fullboth)
(`fullscreen (ding) 'fullscreen)
(_ nil))))
(global-set-key (kbd "s-m") 'zoom)
This keyboard shortcut in the last line of the code goes well with my global to Mac cmd+m key binding that I described initially. You could customize it to whatever suits you. I am used to pressing cmd-m on launching most apps until it fits screen and Emacs is one of them for me. So I don't bother with the initial-frame-alist setting.
I went on to complete the feature-set I wanted by adding the following code tonight.
;; This defines ctrl-cmd-f to do the same as clicking the toggle-fullscreen titlebar
;; icon usually meant for the "View -> Enter/Exit Full Screen" menu option in
;; Mac apps
(defun toggle-fullscreen() "toggle-fullscreen, same as clicking the
corresponding titlebar icon in the right hand corner of Mac app windows"
(interactive)
(set-frame-parameter
nil 'fullscreen
(pcase (frame-parameter nil 'fullscreen)
(`fullboth nil)
(`fullscreen nil)
(_ 'fullscreen))))
(global-set-key (kbd "C-s-f") 'toggle-fullscreen)
; For some weird reason C-s-f only means right cmd key!
(global-set-key (kbd "<C-s-268632070>") 'toggle-fullscreen)
A couple of notes:-
If you're just learning to use pcase from this code, be careful not to make the same mistake as I did by misreading the backquote as a quote in the docs.
fullscreen is an alias to fullboth and is not a misnomer like the latter is as a term for what it means and hence I have not only handled that case as a value for (frame-parameter nil 'fullscreen) but use that whenever I want to set-frame-parameter to fullboth
HTH
The answer given at https://stackoverflow.com/a/1029065/351716 works for me (with GNU Emacs v24.2.1). To reprise, define the following function in your .emacs file:
(defun x11-maximize-frame ()
"Maximize the current frame (to full screen)"
(interactive)
(x-send-client-message nil 0 nil "_NET_WM_STATE" 32 '(2 "_NET_WM_STATE_MAXIMIZED_HORZ" 0))
(x-send-client-message nil 0 nil "_NET_WM_STATE" 32 '(2 "_NET_WM_STATE_MAXIMIZED_VERT" 0)))
For convenience, you can bind the command to a key. I use the C-z key, which would otherwise minimize the frame, which I have no need for, but always find annoying when I hit it accidentally:
(global-set-key (kbd "C-z") 'x11-maximize-frame)
As I noted in the comment I added to that answer, using this command repeatedly cycles between the normal frame state and the maximized state, but one little annoyance: in between those two, there's a strange state where the frame is almost but not quite vertically maximized. But that's a minor problem.
I'm running Emacs 23.3.1 on Mac OS X. When I have linum-mode enable some lines are not numbered. Sometimes when my cursor scrolls past a line that is not numbered its number will appear and then sometimes it will disappear again. Is there away to prevent this from happening?
From your screenshot, it looks like lines with only comments are not numbered. Dunno why.
Perhaps there is another overlay at such positions, and it has a higher priority, thus masking the line-number overlay. Try turning off font-lock temporarily, to see whether that affects things. Then try increasing the priority of the line-number overlays. For a quick test, do this:
(defun foo ()
(dolist (ov linum-overlays)
(overlay-put ov 'priority 2000)))
(add-to-list 'post-command-hook 'foo t t)
If that helps, then instead of that, do the overlay-put (but try with a ower priority, say, 200) in function linum-update-window. IOW, add the priority when the overlay is put on the text.
I am using emacs on MacOS 10.6 with Terminal. I have a white background.
It's very hard to read quoted C++ strings. They are coming up in pale green. Keywords are in turquoise.
After searching through the source I cam across cpp.el and have determined that I am using the cpp-face-light-name-list instead of cpp-face-dark-name-list.
Apparently this function is supposed to chose the correct list based on the background color:
(defcustom cpp-face-default-list nil
"Alist of faces you can choose from for cpp conditionals.
Each element has the form (STRING . FACE), where STRING
serves as a name (for `cpp-highlight-buffer' only)
and FACE is either a face (a symbol)
or a cons cell (background-color . COLOR)."
:type '(repeat (cons string (choice face (cons (const background-color) string))))
:group 'cpp)
But it doesn't seem to be working.
What should I put in my .emacs file so that I get the cpp-face-dark-list instead of cpp-face-light-list?
Thanks!
I have the same problem, my chosen themes are always unreadable on the terminal. The answer is to use the color-theme package, as others have said, then select one theme for Emacs in a terminal, and another theme for Emacs running in its own window, just like this:
(require 'color-theme)
(setq color-theme-is-global t)
(if window-system
(color-theme-deep-blue) ;; Emacs in own window
(color-theme-dark-laptop) ;; Emacs in tty
)
In Emacs, you can type M-x color-theme-Tab to get a list of available themes. Equally, you could add hooks for major modes to change the color-theme depending on what sort of code you are editing.
As suggested in one of the comments - check out the color-theme package. It's a much more generic solution to problems such as yours and it's much easier to use than manually adjusting font faces.
If you explicity set the default-face's foreground to black and background to white ( M-x customize-group basic-faces), font lock will make sure everything is readable automatically. Those two colors are the only ones you need to set if all you need is enough contrast to have font lock be readable.
I have tried colortheme.el, and especially with emacs23 it tends to make things less rather than more readable, I ended up having to restart in order to recover faces that it set to unreadable foreground/background combos and did not reset.
might be worthwhile to make sure your terminal is color enabled:
export TERM=xterm-256color
This is another way to do it, and it's especially handy if you use the daemon mode in Emacs 23+. While using daemon mode, one is sometimes using a graphical client and some other times a terminal client. The "snippet" below tries to figure out what client you are using, and then switches to the appropriate theme (from color-theme-choices). Found it on emacswiki.
(require 'color-theme)
(eval-after-load "color-theme"
(color-theme-initialize))
;; http://www.emacswiki.org/emacs/ColorTheme#toc10
;; select theme - first list element is for windowing system, second is for console/terminal
(setq color-theme-choices
'(color-theme-tangotango color-theme-standard))
(funcall (lambda (cols)
(let ((color-theme-is-global nil))
(eval
(append '(if (window-system))
(mapcar (lambda (x) (cons x nil))
cols)))))
color-theme-choices)
(require 'cl)
(fset 'test-win-sys
(funcall (lambda (cols)
(lexical-let ((cols cols))
(lambda (frame)
(let ((color-theme-is-global nil))
(select-frame frame)
(eval
(append '(if (window-system frame))
(mapcar (lambda (x) (cons x nil))
cols)))))))
color-theme-choices ))
(add-hook 'after-make-frame-functions 'test-win-sys)
Background information:
I'm on a Mac, and I've just upgraded to Emacs 23.1 via http://emacsformacosx.com/. There are a few issues, notably the lack of full screen ability.
I've attempted to get around this last issue by installing Megazoomer, which adds a global input manager bound to Cmd-return. This causes the currently forward application to maximise. However, Emacs reports that <s-return> is undefined. I've never seen an s-[key] mentioned before, and Google isn't forthcoming with an answer.
So, two parts:
What does s-[key] mean? This is purely for my satisfaction; and
Can I tell Emacs to ignore this key combination and let the key combination carry through to the system (so that hopefully I can have full screen Emacs back again)?
EDIT: so 1) is resolved, and as to 2) I've got: (global-set-key (kbd "<s-return>") 'ignore), which at least stops the error. However, Emacs still swallows the key combination, which isn't ideal.
It's the Super key, like M- is the Meta key (alt key on a PC keyboard, Command key on your keyboard) and C- is the Control key.
I have of course never actually seen a super key on my keyboard... they are from a long gone era. Wikipedia has an image of this impressive "Space Cadet keyboard" which has all the modifiers you'll ever need:
With plain Emacs 23.1 on a Macbook Pro, I can map the right option key to super by
(setq ns-right-option-modifier 'super)
Your other choice seems to be the function key, which would be ns-function-modifier. However, fn might have other uses, whereas Emacs’ default is to map ns-right-option-modifier to ’left (ie, the same effect as the left option key, which I at any rate need to get the # character!), so the right option key is to some extent redundant.
Left-handers may want to reverse this.
For the question about what the s-[key] means, on ubuntu box it means the Windows® shaped key. What it means on the OSX systems, I do not know.
As for maximizing windows, could you try this?
(It should work, iif OSX runs an X server somewhere underneath it all)
(if (equal (window-system) 'x)
(progn
(defun toggle-fullscreen ()
"Toggles fullscreen"
(interactive)
(x-send-client-message nil 0 nil "_NET_WM_STATE" 32
'(2 "_NET_WM_STATE_MAXIMIZED_VERT" 0))
(x-send-client-message nil 0 nil "_NET_WM_STATE" 32
'(2 "_NET_WM_STATE_MAXIMIZED_HORZ" 0)))
(global-set-key (kbd "C-c C-y") 'x-clipboard-yank)
(global-set-key (kbd "M-RET") 'toggle-fullscreen)))
This little snippet is what I use to toggle fullscreen on my *nix computers. And yanking from X's clipboard is a neat ability to have.
As for how to set keybindings, use global-set-key for mode independent keybindings.
(Add it to your .emacs file if you want it to be permanent.)
(setq ns-command-modifier nil)
That is supposed to do what you want. However, it's having somewhat unpredictable behaviour on machine when I test it, so be warned.