Eval form after symbol has been defined
python if variable exists
python check if self variable exists
eval definition in medical
python undefined variable error
python check if variables is defined
perl defined in python
I have a function
permanent-set-key that automates adding key-binding definitions, both local and global, to an init file. When the user requests to add a local key-binding, the function determines the current local keymap using this pretty robust approach from the answer to a question I asked earlier.
So now I know the symbol-name of the
(current-local-map) and have the appropriate sexp that will define the desired key, for example:
(define-key python-shell-map [3 6] 'python-describe-symbol)
However, at the time of initialization, usually such maps are undefined, so eagerly evaluating the form above will cause error.
What is a robust programmatic approach to scheduling these forms to be eval-ed at the appropriate time?
What I have been doing so far has been to assume a minor mode exists for the current local map, and then guess the name of the minor mode's file in order to wrap the above sexp in an
eval-after-load form, according to the convention
foo-mode-mode-map. For example, this was generated automatically:
(eval-after-load 'dired '(define-key dired-mode-map  'run_gdmap_dired))
and happens to work (since there does indeed exist a
dired mode and file).
For the first example, this approach does not work: there does not exist a
python-shell minor or major mode. The major mode
comint-mode handles several "sub-modes" so adding to it customizations desired for only the "python" version does not seem appropriate.
How can I determine the name of the file which will define a symbol such as
I suppose I could use after-load-functions and check for all new symbols that may have been defined, but maybe there is a more direct solution.
I just found my own answer, thanks to an
apropos that I hadn't noticed earlier:
(symbol-file SYMBOL &optional TYPE) For more information check the manuals. Return the name of the file that defined SYMBOL. The value is normally an absolute file name. It can also be nil, if the definition is not associated with any file. If SYMBOL specifies an autoloaded function, the value can be a relative file name without extension. If TYPE is nil, then any kind of definition is acceptable. If TYPE is `defun', `defvar', or `defface', that specifies function definition, variable definition, or face definition only. [back]
So this works:
(symbol-file 'python-shell-map)--> "/usr/share/emacs/23.3/lisp/progmodes/python.elc"
Just to make this more explicit:
(format "(eval-after-load \"%s\" '%s)" (symbol-file keymap-symbol) define-key-sexp)
ARS-NC., The other symbols have been defined previously. Evaluation of the Discharge Coefficients The discharge coefficients for the low rectangular The intercept is 0.3721, from which Cri 0.558 and the slope is 0.3136, from which — Ctl %l = 0.3136 15 lL L and, since ZL = 0.789, CTL In equation form CRH = CRL = 0.558 (25) Because a symbol can contain more than one character, we have a complete symbol when a character that doesn’t belong in a symbol is encountered. Non symbol characters include whitespace (space, tab, newline etc), and syntax characters such as parenthesis, (, ). To determine whether the end of a symbol has been reached we need to look ahead by one character.
An alternative path to get the behavior you're looking for might be to generate code of the form:
(add-hook '<MAJOR-MODE>-hook (lambda () (local-set-key <KEY> <BINDING>)))
this way you don't need to care about the keymap's name nor the file name in which that keymap variable is initialized.
Testing if a Variable Is Defined - Python Cookbook [Book], Python doesn't have a specific function to test whether a variable is defined, since all variables are expected to have been defined before use, even if give rise to undefined variables, such as processing configuration files or web forms, are Using an explicitly specified dictionary for exec , eval , and execfile is advisable YN3 John Doe has been assigned Temporary Additional Duty Under Instruction to your command for 30 days and you want his performance for this period noted. You should submit which of the following documents?
Corrected after comments: that works for me with shipped python.el of 24.3:
(eval-after-load 'python-mode (lambda () (funcall (define-key inferior-python-mode-map MY-KEY COMMAND))))
Mathematics for Physical Science and Engineering: Symbolic , z has now been assigned a value, and that may cause us trouble later unless we Moreover, if we (carelessly) repeat the command x1=z+5 while z is still set to If x has been defined, the right-hand x is replaced by its value when evaluation symbols representing numbers can be converted to decimal form (at machine After the problem has been clearly defined, the next step in the PDLC is to create the plan or algorithm. This plan is usually written as a flowchart, and is in written in an ordinary language, such as _____.
Another solution that I ended up using eventually was to use the
after-load-functions hook to define a function
eval-after-sym-loaded, which evaluates a 0-ary function as soon as the given symbol becomes bound after a
load-file call--possibly immediately:
(defun eval-after-sym-loaded (sym fun) "funcall the 0-argument function `fun' only after `sym' has been bound after a `load-file' if `sym' is already bound, call `fun' immediately" (if (boundp sym) (funcall fun) (push (cons sym fun) eval-after-sym-loaded-alist))) (defvar eval-after-sym-loaded-alist nil "alist used internally by eval-after-sym-loaded") (defun eval-after-sym-loaded-hook (file-loaded) (setf eval-after-sym-loaded-alist (loop for (sym . fun) in eval-after-sym-loaded-alist if (boundp sym) do (funcall fun) else collect (cons sym fun)))) (add-hook 'after-load-functions 'eval-after-sym-loaded-hook) ;; example usage: (eval-after-sym-loaded 'html-mode-map (lambda () (message "the symbol 'html-mode-map has been loaded!"))) (eval-after-sym-loaded 'js-mode-map (lambda () (message "the symbol 'js-mode-map has been loaded!")))
Advances in Practical Applications of Scalable Multi-agent , Propositional symbol and symbols of the form ¬pi(i ≥ 0) stand for means that the evaluation result, may change as more information is added to the program. Two major semantics for ELP have been defined: (1) answer set semantics , Related: Strings as variable references in R Possibly related: Concatenate expressions to subset a dataframe I've simplified the question per the comment request. Here goes with some example data.
The Abandoned Generation: Democracy Beyond the Culture of Fear, Character education, as it has been defined among conservative cultural warriors such as Lynne Cheney, is a euphemism for promoting pedagogical practices 4. Gross income is defined as income after taxes and other withholdings have been True False subtracted from net income. 5. Interest rates and fees are about the same on all credit cards. True False 6. Compound interest is when only the amount of money deposited earns interest. True False 7.
Replace symbols with values without evaluation, Assuming that variables are already defined and you don't want to bother with listing the symbols, and you want to have a function that does it in one go: \begingroup Also, this doesn't work when the variables has already been defined. This question in its base form is a duplicate, but since I cannot find the original, and Our online evaluation forms can be helpful for any organization. Get started by picking a free evaluation template below or starting your own basic evaluation form. Once you have selected your form, use the JotForm form builder to format and customize your evaluation form to fit your needs.
eval, Later versions of the Lisp eval function have also been implemented as compilers. The eval function in Lisp expects a form to be evaluated and executed as It depends if you just care that the variable has been defined or if you want it to have a meaningful value. Checking if the type is undefined will check if the variable has been defined yet. === null or !== null will only check if the value of the variable is exactly null. == null or != null will check if the value is undefined or null.
- If I understand you correctly, both the other post you cite and your suggestion that you need a symbol whose value is the
current-local-mapare mistaken/misguided. You do not.
define-keytakes a keymap as its argument, so you can just pass it
(current-local-map)and not know or care what symbol(s) might be bound to that keymap value.
- Drew, of course that will work when the current local map is the one I intend to modify, but as I noted in the other post, I am modifying various local maps at the time of initialization, ie, making local map customizations persistent. The value of
(current-local-map)at initialization does not have to do with the various local maps that I have customized.
- You might feel that you want a symbol, so you can do what you are trying to do here. Without knowing all that you are trying to do, I would probably instead just add the
define-keyto the appropriate mode hook (you presumably know the current
major-modewhen you generate the
define-keycode). It seems (again, without knowing all that you are doing) that you are reaching for indirection (symbols, file loading) that isn't really needed. I think all you need to know is the mode, and add
(define-key (current-local-map)...)to the mode hook (yes, at startup time).
- I am just automating the process of persistently defining keys into local maps. When I am in a local map and decide I want to override a keybinding, I don't want to do this operation manually. As in the example above, relying on the major mode does not always work, for example, with
comint-mode. Also, I prefer not to rely on naming conventions and have my code work most of the time. I'd welcome any idea as to how to programatically find the appropriate mode hooks, but this solution seems the most robust, even if it does not make use of the explicitly intended customization mechanisms.
major-modetells you the current mode when you are in it, which is when you add the code to your init file (interactively), right? Whatever local map
comint-mode(or whatever) uses will become current again when you are enter the mode in a new session --- as the value returned by
current-local-map. So if you put
(define-key (current-local-map) KEY CMD)on the mode hook (via your init file), then whenever that mode is entered the key will be bound in the correct map (the then-current local map), whatever the mode might be, and whatever symbols might be bound to the keymap.
- This looks more standard. I can't remember well but I think there is a reason I didn't want to rely on this. I think I wanted to be able to eval something after a
gud-mode"sub-mode" for which a major or minor mode doesn't exist. I just checked and the
pdbcommand is not a mode in itself, unlike e.g.
inferior-python-mode, but is defined in
gud.el. It does seem to manually run a
pdb-mode-hook, but I don't know if it did at the time of the OP.
- I have tried variations of this, it does not work.
eval-after-loadexpects either a file or a
provided symbol, and
inferior-python-mode-mapis neither, so while the sexp above does not err, it never actually evaluates the forms it is provided.
- Right. Unless you are the maintainer of the library in question, in which case you can add as many
provideexpressions as you like, calling anything you like a "feature", this won't help. And it also suffers from the other problem I mentioned wrt depending on a file loading for the map state: it is pretty static. A map can be created dynamically and updated -- that's why we have
current-local-mapetc. The mode command, not necessarily the file top-level, is generally in charge of the map.
- Drew. It would be nice if all libraries provided a stable, standard mechanism for customizing keybindings. From the point of view of my program (the function above), it is very hard to find the appropriate hooks to customize the current context of active keymaps. So your preferred approach relies on 1) Assuming that the current mode is particularly associated with the map, and 2) Assuming that the mode follows a standard naming convention in order to guess the appropriate hook. These assumptions for me have failed at times, but I have yet to find any anomalies by defining custom keys upon the
- Okay, think have the solution. Problem goes away, if the mode-map in question is loaded, which is not the major-mode map. Will correct my answer.
- symbol definition. I suppose that it is possible as you mention, that a keymap is modified/updated after the file-load has defined the keymap symbol, but from the point of view of my program, the
eval-after-loadapproach is less prone to failure. Also, if you insist in using hooks, how would you programmatically find the appropriate hooks for a given mode? What if a mode is derived and does not provide its own hooks?