macosemacs

Emacs question - hash key


I have a Mac Laptop and I am connecting to server running Linux. As Alt+3 is already bound in EMACS to a command, so I cannot insert the hash symbol in a file. I have tried the following solution I found online:

(global-unset-key (kbd "C-3"))
(global-set-key (kbd "C-3") '(lambda() (interactive) (insert-string
"#")))      //I know that C is for CTRL not Alt - I have tried with
M-3 instead as well

and some others as well, but none seem to work. Can you tell me any other way in which I might be able to enter the hash sign (#) in a file.

Aso tried (did not work):

(fset 'insertPound "#")
(global-set-key (kbd "M-3") 'insertPound)

Thank you!


Solution

  • I assume that you have a Mac UK keyboard so Shift-3 is £. On most other keyboards Shift-3 is # as others have said.

    The way I get round it is to change the input source to Australian the only difference is that Shift-3 is now # and Alt-3 is £ (or leave as the emacs binding)

    Input Source setting was System Preferences->Language&text->Input Source
    On later OSX versions (OSX 10.11 definitely but would have been earlier) Input Source setting is System Preferences->Keyboard->Input Source By default this will just show the UK keyboard to see more hit the + at the bottom of the list and add Australian

    The reason I prefer this rather than adding code in emacs is that Shift-3 is # for all apps e.g. including Xcode/Eclipse so I don't have to switch the key according to the app or according to wether I am on a US keyboard or on Windows/Linux etc.