emacs - Eval form after symbol has been defined -


i have function permanent-set-key automates adding key-binding definitions, both local , global, init file. when user requests add local key-binding, function determines current local keymap using this pretty robust approach answer question asked earlier.

so know symbol-name of (current-local-map) , have appropriate sexp define desired key, example:

(define-key python-shell-map [3 6] 'python-describe-symbol) 

however, @ time of initialization, such maps undefined, eagerly evaluating form above cause error.

what robust programmatic approach scheduling these forms eval-ed @ appropriate time?

what have been doing far has been assume minor mode exists current local map, , guess name of minor mode's file in order wrap above sexp in eval-after-load form, according convention foo-mode-mode-map. example, generated automatically:

(eval-after-load 'dired '(define-key dired-mode-map [8388711] 'run_gdmap_dired)) 

and happens work (since there indeed exist dired mode , file).

for first example, approach not work: there not exist python-shell minor or major mode. major mode comint-mode handles several "sub-modes" adding customizations desired "python" version not seem appropriate.

how can determine name of file define symbol such python-shell-map?

i suppose use after-load-functions , check new symbols may have been defined, maybe there more direct solution.

i found own answer, apropos hadn't noticed earlier:

(symbol-file symbol &optional type)    more information check manuals.  return name of file defined symbol. value absolute file name.  can nil, if definition not associated file.  if symbol specifies autoloaded function, value can relative file name without extension.  if type nil, kind of definition acceptable.  if type `defun', `defvar', or `defface', specifies function definition, variable definition, or face definition only.  [back] 

so works:

(symbol-file 'python-shell-map)--> "/usr/share/emacs/23.3/lisp/progmodes/python.elc" 

edit:

just make more explicit:

(format "(eval-after-load \"%s\" '%s)" (symbol-file keymap-symbol) define-key-sexp) 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -