Carbon-emacs: re-enable hash key? - macos

How can I re-enable the hash (#) key in carbon-emacs on the mac? I've tried everything I've come across in google and still can't get it working.
My config file currently looks like this:
(require 'redo+)
(require 'mac-key-mode)
(mac-key-mode 1)
(setq default-input-method "MacOSX")
(setq mac-command-modifier 'alt mac-option-modifier 'meta)
The above has enabled all the Command+Key bindings (such as Cmd+S for saving), but Alt+3 isn't working.
I'd normally work around it but I'm programming in Python and # is rather useful for comments! ;)

How about adding this to .emacs, setting up a macro and then binding M-3 to it:
(fset 'insertPound
"#")
(global-set-key (kbd "M-3") 'insertPound)

I know this is a bit late and the answer has been accepted. However, I have just moved from Linux to MacOS and had the same problem.
Posted my response on a similar question:
https://stackoverflow.com/a/21722619/1308653
I hope this helps someone.

Have you thought about moving to Aquamacs?

Related

emacs lisp: how to set tab key to bind different function?

I'm trying to set the tab key to map a function.
In my application, with tab I have to select next window in screen.
I tried to define a simple function that displays a message; I used (global-set-key) to map this function on "M-h"
(global-set-key (kbd "M-h") 'hello)
It worked, message is displayed.
Now, I tried same thing with tab-key
(global-set-key "\t" 'hello)
Apparently I don't receive any error.
But, tab key doesn't display anything.
I'm using emacs on windows, but tab key works correctly in other situations.
Any suggestions?
Hmm, I'm not sure what's wrong, doing
(defun hello () (interactive) (message "hi!"))
(global-set-key "\t" 'hello)
seems to work fine for me. Does your hello function look similar? The only thing I can think to suggest is trying (kbd "TAB") rather than "\t" in the call to global-set-key. A lot of code I've seen in the wild and that I've written in my config does this. I'm not sure if there's any difference, but it's worth a shot!

Why does shell mode display some rubbish code?

When I use bower in M-x shell, as you can see in the picture, some rubbish code is displayed.
However M-x ansi-term works well
What could be the problem ? Is it possible to make shell mode display properly ?
Those symbols are ANSI escape sequences that the terminal emulator uses for visual effects like changing the color of text. shell-mode apparently doesn't know how to display these codes by default. What you want may be Term Mode:
Some programs (such as Emacs itself) need to control the appearance of the terminal screen in detail. They do this by emitting special control codes. Term mode recognizes and handles ANSI-standard VT100-style escape sequences, which are accepted by most modern terminals, including xterm. (Hence, you can actually run Emacs inside an Emacs Term window.)
Try the solution given in Cucumber's ANSI colors messing up emacs compilation buffer:
(require 'ansi-color)
(defun colorize-compilation-buffer ()
(toggle-read-only)
(ansi-color-apply-on-region (point-min) (point-max))
(toggle-read-only))
(add-hook 'compilation-filter-hook 'colorize-compilation-buffer)
that works beautifuly for me on emacs24.
ps: to colorize even more the shell output I like to play with
M-x highlight-regexp RET a regexp, i.e. \[OK\] RET a color (make use of TAB to see choices)
or
(add-hook 'shell-mode-hook (lambda () (highlight-regexp "\\[OK\\]" "hi-green-b")))
and (add-hook 'shell-mode-hook (lambda () (goto-address-mode ))) to make URLs clikable. Looking for the same stuff for file paths.
edit: making file paths clickable is as easy as using compilation-shell-minor-mode :)
edit2: my sources: http://wikemacs.org/index.php/Shell
WRT to bash, sometimes setting $PAGER helps here, i.e.
PAGER=cat

How do I set fonts on Emacs for Mac?

I downloaded Carbon emacs 23.3.1 (x86_64-apple-darwin, NS apple-appkit-1038.35) from http://emacsformacosx.com/. It defaults to using Monaco, and I would like to change it to use Inconsolata-dz. So I added:
(set-default-font "-apple-Inconsolata-dz-medium-normal-normal-*-10-*-*-*-m-0-iso10646-1")
to my ~/.emacs file. However, after I restart, it is still Monaco. It discovered that Option-T (or maybe Command-T) brings up a font dialog, and if I select Inconsolata-dz from that, it works great. But if I restart, it is back to Monaco. So I tried setting the font from the menu, and then going to Customize Faces and saving it, but still it does not work. The interesting thing is that if I do M-x describe-font after changing the font from the Option-T dialog, it says -apple-Inconsolata-dz-medium-normal-normal--10--*-*-m-0-iso10646-1.
So it looks like Emacs is simply ignoring this font for some reason. Why is that, and what can I do to get it to use this font?
Update: I tried Donkopotamus and Joost Diepenaat's recommendations and they also did not work, although I ended up getting Times as my font, instead of Monaco. However, they work great if I just use the Inconsolata (not Inconsolata-dz). So I'm wondering if there is some problem with fonts with a dash in their name?
Update2: Why is this off-topic? The close message says "questions [should ...] relate to programming or software development in some way"; many developers use emacs, and getting settings right is important. The top two entries on a search for "programming fonts" have a combined 150; so font configs seem to be important to programmers. Anyway, if it is off-topic, where is the appropriate place to post it?
I use plain Inconsolata. From my emacs.d/init.el:
(set-face-attribute 'default nil
:family "Inconsolata" :height (case system-type
('gnu/linux 130)
('darwin 145)) :weight 'normal)
If you're only running on OSX, you can simplify that to
(set-face-attribute 'default nil
:family "Inconsolata" :height 145 :weight 'normal)
I use Inconsolata. In my .emacs I simply set the default font to Inconsolata using
; check if we're on OSX
(when (featurep 'ns-win)
(custom-set-faces
'(default ((t (:height 140 :width normal :family "Inconsolata")))))
)
I've seen this behavior on Mac, and now I do this in my emacs init file:
(set-face-attribute 'default nil :foundry "apple" :family "Anonymous_Pro")
That works nicely for me, but note that I'm using a newer (HEAD) version of Emacs. You would presumably need to use "Inconsolata-dz" as the value for :family.
Without this, new frames would always pop up using the system-wide default monospaced font (Monaco), which is likely what's happening for you.
P.S. Your Emacs version is a Cocoa Emacs, not a Carbon Emacs.
Are you sure your .emacs is being read in? For example, are other things in there taking effect?
Assuming that is okay, I use this in my init file:
;; (insert "\n(set-default-font \"" (cdr (assoc 'font (frame-parameters))) "\")\n")
Note that it is intentionally commented out. Now set your font using Command-T, then go to the end of the above line and do C-x C-e . It will insert a command to set your font to whatever it is now. Save/exit/enter Emacs and you should have your font.

Making Aquamacs scrolling more like Emacs

When I used emacs, I used to be able to set the mark and highlight full pages for yanking using C-v, or scroll-up. However, in Aquamacs if I set the mark then hit C-v it loses the mark and stops highlighting. I noticed that in Aquamacs C-v is instead mapped to aquamacs-page-down, so I tried adding the following command to my site file:
(define-key osx-key-mode-map "C-v" 'scroll-up)
and this didn't successfully remap the key. I then tried something similar:
(define-key global-map "\C-v" 'scroll-up)
and still nothing. Aquamacs very stubbornly hangs onto the mapping to aquamacs-page-down. I noticed, however, that there's an additional function, aquamacs-page-down-extend-region, which does exactly what I'm talking about. Its key sequence, however, is , and I have no idea how to input that. I tried "shift-control-v" to no avail.
Has anyone been able to get Aquamacs to scroll pages while maintaining the mark?
I've found a way to get this to work, for posterity's sake.
Paste this into the .emacs file:
;; Enable scrolling to maintain mark if set
(defun scroll-down-maintain-mark ()
(interactive)
(if mark-active
(aquamacs-page-down-extend-region)
(aquamacs-page-down)))
(defun scroll-up-maintain-mark ()
(interactive)
(if mark-active
(aquamacs-page-up-extend-region)
(aquamacs-page-up)))
(define-key global-map "\C-v" #'scroll-down-maintain-mark)
(define-key global-map "\M-v" #'scroll-up-maintain-mark)
hitting C-SPC C-v C-l, the last to recenter screen, seems to show that it does indeed preserve the mark.
and subsequent copy and yank works fine
perhaps this behavior added on newer Aquamacs.

What does "s-[keyname]" refer to in Emacs, and how do I tell Emacs to ignore it?

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.

Resources