Emacs defines ` to be used for abbrevs in f90 mode. How do I change this so some other key, like e.g. # ? I think, I found the relevant lines in f90.el:

(defvar f90-mode-map
  (let ((map (make-sparse-keymap)))
    (define-key map "`"        'f90-abbrev-start)

but my attempts at mimicking this syntax usually lead to errors.

Thanks in advance for any help.


So I followed the advice of Aaron Harris and added:

(eval-after-load 'f90
  '(define-key f90-mode-map (kbd "#") #'f90-abbrev-start))

to my .emacs. Now when I open a Fortran file and hit

C-h k #

I get the following text:

# runs the command f90-abbrev-start, which is an interactive compiled Lisp function in `f90.el'.

It is bound to #, `.


Typing C-h or? lists all the F90 abbrevs. Any other key combination is executed normally.

But still


is expanded to subroutine while


is not. Do I misunderstand something here?

1 Answer 1


EDIT: Okay, after actually looking at the f90-mode code, it looks like f90-abbrev-start doesn't really do much except call self-insert-command and relies on every entry in f90-mode-abbrev-table to start with a backquote.

One solution would be to modify f90-mode-abbrev-table so the abbreviations all start with a hash character instead of a backquote, but I'm not sure how to do this in a way that isn't messy.

The other possibility that occurs to me would be to remap the key on the input event level rather than the command level, so that the call to self-insert-command sees a backquote. I think this should work:

(define-key f90-mode-map (kbd "#") (kbd "`")

Original, not-particularly-helpful answer:

From the snippet you posted, you probably want to write:

(define-key f90-mode-map (kbd "#") #'f90-abbrev-start)

Note that the only significant departure from the code in the snippet is the lack of defvar and let forms. This is because those are being used to define the variable f90-mode-map, and you just want to modify the variable as it already exists.

The other two minor changes here are less important:

  1. Exchanging "#" for (kbd "#") does nothing here (since (kbd "#") returns "#"), but it's good practice to get into when defining key bindings, because kbd will return the correct answer in pretty much all circumstances, whereas a bare string won't always work.
  2. The use of the sharp quote (#'f90-abbrev-start vs. 'f90-abbrev-start) just tells Emacs that we are talking about the function f90-abbrev-start rather than the variable f90-abbrev-start (which may or may not be defined). I don't believe this matters unless you're byte-compiling the file in question, but putting it in is considered good practice. Also, it makes function references easier to distinguish visually, which I find helpful.
  • Thanks for your help. I've made some advances, something still doesn't work.
    – Laurent
    Feb 16, 2016 at 20:04
  • @Laurent: Answer updated. Hopefully this new approach will work for you. Sorry for not doing more research before jumping in with my original answer. Feb 16, 2016 at 20:50
  • Works like a charm now!
    – Laurent
    Feb 17, 2016 at 6:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.