reddit / emacs

Where is global-map initially populated ?

Fofeu · 2022-02-28 08:37
Hello, As the question asks, where is the variable `global-map` initially filled with values ? It is defined in `subr.el` as `nil` and many keys are defined in `bindings.el`. However, I seem to miss something because I can't for instance find where letters are bound to `self-insert-command`. Thanks in advance
algon-ns · 2022-02-28 09:16
Hi, As I see it, emacs src directory --> cmds.c --> line 263 mvh Algon
Fofeu · 2022-02-28 15:50
I'm not an expert in the Emacs C source code, but the location you indicate seems to be where `self-insert-command` is *defined*, not where it is *bound*. I'm looking for a location where I can find (among other things) something like (define-key global-map (kbd "a") self-insert-command) (define-key global-map (kbd "b") self-insert-command) ...
algon-ns · 2022-02-28 16:50
I would not code it that way, I would test, if the input were bound explicit, and if not make it self-insert..... If I get the time, i'll look into it, at a later time. ....but it's about 40 years since I lived by programming, so something must have happened since then mvh Niels
7890yuiop · 2022-02-28 20:43
It's directly in the definition of the `global-map` variable: (defvar global-map (let ((map (make-keymap))) ... (let* ((vec1 (make-vector 1 nil)) (f (lambda (from to) (while (< from to) (aset vec1 0 from) (define-key map vec1 #'self-insert-command) (setq from (1+ from)))))) (funcall f #o040 #o0177) (when (eq system-type 'ms-dos) ;FIXME: Why? (funcall f #o0200 #o0240)) (funcall f #o0240 #o0400)) ...))
Fofeu · 2022-02-28 20:53
Weird, that's not how it's defined on my installation. `C-h v global-map` points to `subr.el.gz` where it is defined as `(defvar global-map nil)` .
7890yuiop · 2022-02-28 21:25
Right, this has changed recently (only a year ago). Previously it was done in the C function `keys_of_cmds`. You can find everything you're looking for in the relevant commit: https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=d6f30e5632b1c9cf43ebfbdbf164d5c54be33475
arthurno1 · 2022-02-28 22:51
> many keys are defined in bindings.el Bindings for global map can be defined in many places. It is global == always available.
arthurno1 · 2022-03-01 11:12
> I'm not an expert in the Emacs C source code, but the location you indicate seems to be where self-insert-command is defined, not where it is bound. I am not an expert either, but a good tip is to look where the function is defined. It is often (not always) bound somewhere else in the same file too. Usually for lisp sources, not for C sources. It is not a rule, but in many cases it is so. It does not matter the exact place where it is bound. You just need to know which functions are bound. You can re-bound global map anywhere you want if you need to modify the behaviour.