(defun some-function (beginning end)
(message "The region is active, and is from %d to %d" beginning end)
(message "The region is still there (from % d to %d), but it is inactive"
The use of (interactive "r") means that the parameters beginning and end will automatically ...
The core point is that there is a difference between a function and a command.
In Emacs lisp, functions are not interactively callable by default. That means you can't access them via M-x or bind them to a key or mouse click. If you want to do that, you need to explicitly declare the function to be interactive, which you do by adding an (interactive) form ...
From the documentation of insert-char, I cannot see why
(insert-char "GREEK SMALL LETTER EPSILON")
It doesn't work because insert-char understands Unicode character names only when called interactively (e.g. via C-x8RET or M-xinsert-charRET), as stated in its docstring:
Interactively, prompt for CHARACTER. You can specify CHARACTER ...
Hard to believe that people described this here without also giving you links to Emacs's own descriptions of this:
In the Emacs manual, node Arguments.
In the Elisp manual, node Prefix Command Arguments.
"Ask Emacs!": C-h i, choose a manual, i prefix argument RET.
In a nutshell, though this is said well enough by other answers here, and is described in ...
According to shell's interactive form, as long as current-prefix-arg is non-nil, shell will ask user a buffer to use, so you can set current-prefix-arg to non-nil (4 is used in following as an example):
(let ((current-prefix-arg 4))
or simulate executing shell with a prefix 4 (M-4 M-x shell):
(execute-extended-command 4 "...
When raw prefix Interactive Code "P" is used, the argument is passed on as it is whereas "p" converts the arg to a number.
After evaluating the below elisp, try out C-u M-x my/fn-with-num-arg and then C-u M-x my/fn-with-raw-arg to see the difference because C-u passes a list argument (4).
(defun my/debug-fn (arg)
(if (numberp arg)
While it is entirely subjective, I would suggest only making functions interactive if you actually expect them to be called that way. Many functions are intended to be used as building blocks rather than end-user commands.
It can be simpler to define a non-interactive function. While these factors are important for any function, they are particularly ...
You are looking for repeat, bound by default to C-x z. The
first part of the docstring:
Repeat most recently executed command.
If REPEAT-ARG is non-nil (interactively, with a prefix argument),
supply a prefix argument to that command. Otherwise, give the
command the same prefix argument it was given before, if any.
If you ...
If you want to call an interactive function from within elisp, but
call it as if you invoked it interactively (e.g., via M-x some-command), you can wrap it in the call-interactively function.
The first part of the docstring reads:
(call-interactively FUNCTION &optional RECORD-FLAG KEYS)
Call FUNCTION, providing args according to its interactive
Interactive simply provides a way to call the function via M-x. You can use venv-workon normally, like any other emacs-lisp function. Here's an example:
For more detail on what interactive does, see Using Interactive from the Elisp docs. Essentially, interactive marks a function as a ...
You can look up the stack using the backtrace frames, here is an implementation getting the name of the current function.
Can functions access their name?
The code in that question looks up the stack until it finds the frame representing a function call which is the current function, simply continue to move up the backtrace frames until you find the second ...
Just to add a bit more detail to @kaushalmodi's answer (and useful test case):
The raw argument lets you distinguish between arguments provided with universal-argument and digit-argument.
With a numeric prefix arg there is no way to distinguish the universal argument C-u from a prefix arg of 4 (i.e. C-4). With the raw argument these are different: (4) vs ...
buffer-file-name is a function, but not an interactive command. M-x calls execute-extended-command, so can't be used on non-command functions.
For more information, see What is the difference between a function and a command?.
Others have mentioned some reasons for not making a given function into a command. Here is another: user discovery and access to commands.
If you ever manipulate or access commands interactively by name (e.g. M-x, C-h a).
(Or if you ever manipulate them by program, then you typically want them distinguished from other functions. But you might argue that ...
Forms in the function body are executed in order, just as you would expect.
When you choose "y" if does not "jump" past the first message call. If looks like it did because the first message gets immediately replaced by the second one.
To check that this is true, open the *Messages* buffer and then do M-x foo. You will see that foo adds two messages to the ...
You ask several related questions, but this is the main one, I think:
How does one find out what name emacs gives to a key such as the one labeled pause/break on my keyboard?
For Emacs's description of a key, use C-h k.
So C-h k, then hit the Pause key. Emacs probably tells you this:
<pause> is undefined
So you now know that Emacs describes that key ...
It sounds like you should extend tramp-methods, adding a new method which is similar to the sudo method but uses qsub -I instead. You would then be able to use a multi-hop tramp path to first connect to the head node and then to connect to a compute node.
This is because read-char is advised to have special behaviour. When running in 'multiple-cursors-mode' it caches the character read the first time. If this cache is full then it does not ask for a character again.
Whatever function is called by "c" in the interactive description is not advised in this way.
The implementation is incredibly hackish: for ...
If it's ok, that the function isn't interactive in the first
place, something like this might work.
(defmacro define-noninteractive-minor-mode (mode doc &optional
init-value lighter keymap
`(cl-macrolet ((interactive (&rest _)))
So you want to invoke a command and have a given string automatically inserted at that command's interactive prompt.
You can do this using minibuffer-setup-hook, and there is a handy macro which takes care of adding and removing the desired function to this hook, while ensuring that it only runs when you wanted it to run:
Given the function
(defun foo (arg1 arg2)
(interactive (list 'interactive-value1 'interactive-value2)
(message "%s %s" arg1 arg2))
You would get
(foo 'value1 'value2) => "value1 value2"
(call-interactively 'foo) => "interactive-value1 interactive-value2"
And when actually using foo as a command
M-x foo RET => "interactive-value1 interactive-...
In addition to built-in ways to read single events such as read-char and read-char-exclusive, here's an option to read a single character, but also specify which characters are acceptable input:
(defun read-char-picky (prompt chars &optional inherit-input-method seconds)
"Read characters like in `read-char-exclusive', but if input is
not one of CHARS, ...
Here's a more elegant way of doing it:
(defun foo (arg)
(list (if (consp current-prefix-arg)
(read-number "Number: ")
(message "prefix = %0d" arg))
current-prefix-arg holds the value you'd get from (interactive "P"). You can convert it to what (interactive "p") would ...
So as per my earlier comment, Emacs doesn't really support what you're asking for.
I would strongly recommend that you simply define a global command in the normal way, and make it behave appropriately based on the presence or not of a local variable (which could be directory-local). It can still be called from anywhere, but you would ensure that it never ...
Note: Made following minor changes to your code block:
Moved #!/bin/bash into code block header :shebang #!/bin/bash to automatically set executable file permissions when block is tangled into dir-input.sh.
Added debug code to show $TEST_DIR was assigned correctly from read input_variable.
#+BEGIN_SRC sh :results output :export ...
There is also repeat-complex-command (normally bound to C-x ESC ESC as well as several others (that's the one I use, so I remember that)). This will go back further in the history to the last command that required interaction (i.e. prompted for input).