Every command is a function, but not every function is also a command.1
A command includes a call to interactive; this is why commands are commonly referred to as "interactive functions". Commands can be invoked via M-x name-of-command RET, and they can also be bound to a key sequence. Regular functions do not include a call to interactive, can not be ...
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 ...
There are two nice packages for working with perl kind of regexes effectively, which should be used together - visual-regexp and it's extension - visual-regexp-steroids. They are great addition to emacs:
M-! runs the command shell-command. This will prompt you for the actual command to run in the minibuffer, which then runs. You can run it in the background by putting a & at the end, just as you would in a terminal. alternatively, you can use M-&, async-shell-command.
The output from the shell command will be placed in a temporary buffer. If you ...
When some key sequence triggers an unexpected command, use view-lossage (bound to C-h l by default) to see what keystrokes Emacs has recently received. This is most useful since Emacs 25 as it now also shows the commands invoked by each key sequence. In earlier releases you'll just see the raw keystrokes.
The interactive special form provides the easiest way to get input from a user.
(defun td (variable)
(insert (format "std::cout << \"%s is: \" << %s << std::endl;" variable variable)))
Here "sVariable:" consists of the "s" code character (read a string) and the prompt. (See Using interactive in the Emacs ...
The documentation for indent-rigidly says:
If called from a program, or interactively with prefix ARG, indent all
lines starting in the region forward by ARG columns. If called from a
program, START and END specify the beginning and end of the text to
act on, in place of the region.
To indent by four columns, just pass the prefix argument with C-u:
You can run emacs --batch f htmlize-my-org --kill where htmlize-my-org is a function you've written that runs htmlize on those files.
You can also pass files on the command line, e.g. emacs --batch --insert ~/foo/file1.org -f htmlize-my-org --kill
As a more complete example, here's a way to run M-x delete-trailing-whitespace on all files in a dir:
$ for ...
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 ...
You could use M-x make-directory DIRNAME RET. The default path is the path to the current buffer folder.
You could bind it to key (like C-x C-f) with (global-set-key (kbd "C-c d") 'make-directory).
You could create buffer in nonexist path with C-x C-f non/exist/path/file.name RET and then create nececcary folders with M-x make-directory RET RET.
find-file uses the buffer-local default-directory value as the default filename (see also find-file-read-args), so all you need to do is bind that value for the scope of the call to find-file:
(let ((default-directory "/home/"))
The command counsel-M-x does this for you:
(ivy) Global key bindings recommends you remap M-x (execute-extended-command) to counsel-M-x in order to avail of its increased Ivy-ness, e.g. via
(when (commandp 'counsel-M-x)
(global-set-key [remap execute-extended-command] #'counsel-M-x))
Alternatively (and more simply), you can just enable counsel-mode and ...
helm-apropos is indeed pretty slow. I think it comes from joining 5
very large lists:
(defun sum-numbers-in-region (start end)
(split-string (buffer-substring start
Because it uses string-to-number, it will treat the the ...
The info reader in Emacs can be accessed with C-h i. There you can jump directly into the some-node node with g (some-node) RET.
Alternatively, you can go to the some-node node by eval'ing (info "some-node").
Note that the info reader on the terminal picks man pages when info nodes cannot be found. There is no "glibc" info node, but just a man page. To ...
Remember that "commands" are just functions, and can be called as such. You can do this:
M-: (shell-command "ls" <arg1here> <arg2here>) RET
If you want to create new buffers, you'll need a bit more lisp.
And if you do this often, you might even ...
re-builder allows on the fly construction of emacs lisp style regular expressions. I don't know if there is an equivalent package for building Perl regular expressions interactively.
See http://www.masteringemacs.org/articles/2011/04/12/re-builder-interactive-regexp-builder/ for more discussion.
You can always check what function some keys are bound to using C-h k. For example, if we type C-h k C-e, we see that it is bound to (move-end-of-line ARG); similarly, C-j is bound to (newline-and-indent).
In this case, it turns out that C-e C-j is a sequence of two commands rather than a single thing. (The same with C-a C-o TAB.) To bind this to a single ...
You can use the following emacs lisp code saved in htmlize-script.el:
(add-to-list 'load-path "/path/to/htmlize/")
(defun htmlize-files-in-dir (dir)
(htmlize-many-files (directory-files dir t ".org$")))
And then use the following command from a script:
emacs -Q -nw --eval "(progn (load-file \"/path/to/htmlize-script.el\") (htmlize-...
I use C-M-s to search for a regexp. Then I use M-x replace-regexp. Can I save typing the regexp for the second time?
Yes, instead of exiting the incremental search, just hit M-% (which,
by the way, is the global binding for query-replace). This will use
the search string you've just typed and only prompt you for a
This will work both on ...
C-h f this-command-keys:
this-command-keys is a built-in function in `C source code'.
For more information check the manuals.
Return the key sequence that invoked this command.
However, if the command has called read-key-sequence, it returns
the last key sequence that has been read.
The value is a string or a ...
The general way to link multiple key-bindings to a single binding is a Keyboard Macro ((emacs) Keyboard Macros).
Keyboard macros can either be 'recorded' interactively, or written in elisp (in string or vector format). The easiest way to produce the latter is to use the kbd function, so that you can write the keystrokes using the familiar syntax Emacs uses ...