Solution:
So I found the solution ... and do I feel stupid. The problem was not anything to do with emacs at all - it was to do with my keyboard.
So my keyboard has this button which I never use and guess I accidentally pressed called 'F-lock'. I can't post images due to low reputation so see this link for an image: http://az623152.vo.msecnd.net/library/images/2774431.jpg
Toggling F-lock completely changes the functionality of the F buttons. So F3 had become 'Redo' and F4 had become 'New'. So whenever I was actually pressing F3 the computer was not actually even receiving it as f3 but rather
'Redo'.
Thank you for all the comments in helping to debug the problem. Sorry for the time waste!
Original Question:
I have been using f3 in emacs to define a new macro, f4 to finish the definition and f4 again to run the macro for quite some time now.
However, for some reason when I press f3 now it results in a yank instead of the intended macro behaviour.
If I press 'C h k' and then f3 I sometimes get the following (redacted) response:
C-y runs the command org-yank, which is an interactive compiled Lisp
function.
It is bound to C-y.
Sometimes I get this:
C-y runs the command yank, which is an interactive compiled Lisp
function.
It is bound to C-y, <S-insertchar>, <S-insert>, <menu-bar> <edit>
<paste>.
(yank &optional ARG)
The result of doing the same with f4:
C-n runs the command next-line, which is an interactive compiled Lisp
function.
It is bound to C-n, <down>.
(next-line &optional ARG TRY-VSCROLL)
The only recent thing I have started to do is use emacs' org-mode.
How can I get my keys back to their original behaviour? What exactly is causing them to behave like this?
Update:
are you running under terminal or x?
Not running under the terminal - currently using the GUI interface.
when did the change in behavior happen? what was it associated with? new package installation? switch from terminal to X or back? reboot?
There are two things I can think of which may be causing this:
I just recently started using AucTex (v 11.88.6) and org mode.
The 'C h k' f3 sometimes responds that it is bound to org-yank (see above) so I'm leaning towards thinking its something to do with org mode.
Does this behavior also occur when you start emacs with the -Q option?
Yes, even with the -Q option specified the same behaviour results.
Related
I want to remap Control-v for it to use my custom function, but it looks like I can't do that. I'm running emacs in terminal.
(global-unset-key "\C-v")
(global-set-key "\C-v" 'my-cut-or-paste)
If I try to unset first, C-h k just not showing any binding for this shortcut, and C-v just do nothing. If not unsetting shortcut, its not get remapped... The strange thing is how C-h k showing different keys for such shortcuts. For example - one time it can show
r runs the command self-insert-command, which is an interactive
other time (after emacs reload)
i runs the command self-insert-command, which is an interactive
If I try to set my function to such keys (i or r), C-v gets remapped, but those keys (i or r) are mapped to my function too, so I cant type.
Is this kind of 'terminal-related' key sequences? Is it able to do at all? thx.
My guess would be that your terminal is intercepting C-v as a paste-from-clipboard command.
If your clipboard has something that starts with i, you see:
i runs the command self-insert-command, which is an interactive
Similar for "r" or other letters. Emacs is blind to the fact that the "letters" come from a external paste, not from your keyboard. You should check the configuration options of your terminal, to see if you can unset that key.
When using M-x list-processes I get a list of processes.
Is there a way to kill them interactively ? For instance by selecting one in the list, then pressing q or something similar ?
In case it matters, I am using emacs 24.5.1 on osx with emacs prelude.
Note : it is different from this question I want to do it interactively, not from the mini-buffer (as understood by #legoscia already).
In Emacs 25, you can do what you'd expect: in the process list, hit d to "delete" the process under point.
For earlier Emacs versions, I've been using this little function that works using the minibuffer, not the process list:
(defun delete-process-i(p)
(interactive `(,(completing-read"Kill proc: "(mapcar 'process-name(process-list))()t)))
(delete-process p))
After defining it, you can type M-x delete-process-i, and type the name of the process you want to kill, with tab completion.
(I originally wrote it to fit in 140 characters; thus the non-standard layout.)
I'm using emacs 23 (acquamacs) and have installed nrepl.el.
I've evaluated some Clojure code with
C-c C-p
(this key combo is to Evaluate the form preceding point and display the result in a popup buffer.)
Running it has produced a nice popup buffer for me to see the results.
How do I hide this popup buffer? (I don't want to kill it - just get my fullscreen back).
FYI Re this command - I've run this with
C-h k C-c C-p
and got
^C ^P runs the command nrepl-pprint-eval-last-expression, which is an interactive compiled Lisp function in `nrepl.el'.
It is bound to ^C ^P, <menu-bar> <nREPL> <Eval last expression in popup buffer>.
(nrepl-pprint-eval-last-expression)
Evaluate the expression preceding point and pprint its value in a popup buffer.
You haven't provided enough information for anyone to test (that's not a standard global binding), and you haven't even indicated whether the new window is selected; but there's a generic solution which will work regardless.
Add (winner-mode 1) to your init file, and then you can always use C-c<left> to undo the most recent window configuration change (or changes plural, if you repeat the command).
Either that or just press q. I just tried it out with the help buffer and it dismisses the window but not the buffer. However, popup buffers in the style of ac-nrepl does for its autocompletion are meant to simply be dismissed
Always, when asking Emacs questions, say what the key sequence does. C-c C-p does nothing here. TO find out what it does press C-h k C-c C-p and report back. In this case we're invoking 'describe-key and then telling it to describe what C-c C-p does.
I have a confession: I don't know Lisp. Despite that fact, with a bit of help from some co-workers, I managed to write an emacs macro/script which:
switched to shell mode (ie. M-x shell-mode)
disabled truncating lines (ie. M-x toggle-truncate-lines)
started a database console (ie. "mysql")
I was then able to start emacs with that macro using the --script option, and suddenly I had a way to start mysql in a much friendlier environment with a single command :-)
But here's the problem: I changed jobs and left that script behind. Now I'd very much like to re-create that script at my new job, but I no longer have any emacs experts to help me write it like I did at the old job.
Now, I really hate SO posts where someone basically says "please write my code for me", so I don't want to do that. However, if any emacs macro experts could at least give me some pointers (like "here's how you invoke a M-x command in a macro"), or point me to an emacs-macro-writing guide, or otherwise "teach me to fish" on this issue, I would greatly appreciate it.
... and if someone just happened to have a similar script already lying around that they wanted to post, I certainly wouldn't complain ;-)
Most emacs commands (i.e., M-x toggle-truncate-lines) can be translated directly to elisp by wrapping them in parentheses:
(toggle-truncate-lines)
The rumours are true, in lisp you just scatter parentheses around and they make magic.
Now in this case, you can do better. Toggling makes sense for an interactive function, but in a program you don't really want to toggle truncate-lines, you want to turn on truncate-lines. Its the same thing if truncate-lines was turned off to begin with, but you don't know when your program will be run next. Anyways, in Emacs, features are often controlled by a variable. In this case, the variable is truncate-lines, and to turn that feature on, you set the variable to t (which means true).
To do this, use:
(setq truncate-lines t)
We use setq instead of = for assignment, because they made lisp before = had been invented.
For the real scoop you should take a look at Robert Chassel's excellent "An introduction to to Programming in Emacs Lisp". It comes built-in with your emacs, you can get to it with C-h i m Emacs Lisp Intro.
A good way (I think) to start writing elisp functions is to record keyboard macros, and then to analyse them using edit-kbd-macro
For example, if you start recording a keyboard macro using f3, then do interactively all the things you want and terminate the macro using f4, you can see the underlying emacs-lisp commands using M-xedit-kbd-macrof4 (this last f4 is the key binding you'd have used to execute the keyboard macro)
<<shell>> ;; shell
<<toggle-truncate-lines>> ;; toggle-truncate-lines
mysql ;; self-insert-command * 5
RET ;; comint-send-input
Now you can write a script using these functions, looking up the documentation (e.g. C-h ftoggle-truncate-lines) to see if you should call them with special arguments in non-interactive mode.
You should also replace self-insert-command by calls to insert.
This should give you something like the following script, which you can call using emacs --load myscript.el
(shell)
(toggle-truncate-lines 1)
(insert "mysql")
(comint-send-input)
Of course, this might not work as expected the first time, so you might have to eval (setq debug-on-error t) to get debugging information.
What version of Emacs are you using?
In Emacs 24, I have M-x sql-mysql, which does everything you ask and has font-locking.
Frequently, I've dug into apropos and docs looking for something like the following only to give up to get back to the task at hand:
(repeat-last-command)
do the last C- or M- command I just executed (to be rebound to a fn key)
or sometimes the related:
(describe-last-function)
what keystroke did I just mistakenly issue, the effect of which I'd like to add to my bag of tricks. describe-key is close, but requires knowing what I typed.
Am I simply asking too much from my trusty sidekick?
Repeat functionality is provided by the repeat.el Emacs Lisp package, which is included with standard Emacs distributions. From repeat.el's documentation:
This package defines a command that
repeats the preceding command,
whatever that was, including its
arguments, whatever they were. This
command is connected to the key C-x z.
To repeat the previous command once,
type C-x z. To repeat it a second time
immediately after, type just z. By
typing z again and again, you can
repeat the command over and over.
To see additional information about the repeat command, type C-h F repeat RET from within Emacs.
Repeat last command
C-xz
Once you pressed it, just press only
z
after that and it will repeat (without having to press C-x again).
Yes, there is a repeat command. It's called repeat:
You can repeat commands with C-x z, and hit z to keep repeating.
A bit shocking nobody mentioned repeat-complex-command, available from the key binding C-x ESC ESC.
with regards to 'describe-last-function':
There's a variable last-command which is set to a symbol representative of the last thing you did. So this elisp snippet - (describe-function last-command) - ought to bring up the documentation for the thing that immediately happened.
So you could make a trivial working describe-last-function like so
(defun describe-last-function()
(interactive)
(describe-function last-command))
Put that elisp in .emacs or equivalent, and you'll have a M-x describe-last-function.
If you've banged on a few keys or done something that modified last-command since the thing you're interested in, the command-history function might be of interest. You can get that by M-x command-history
Also, M-x view-lossage shows you the last hundred(?) keystrokes you entered. So, you'll be able to see where the command is. It's what i used until i just right now found out about M-x command-history which i think i'll be using with C-h w now.
I'm not really sure, but maybe you are searching for this one?
The command C-xz (repeat) provides another way to repeat an
Emacs command many times. This command repeats the previous Emacs
command, whatever that was. Repeating a command uses the same arguments
that were used before; it does not read new arguments each time.
Emacs Manual, 8.11 Repeating a Command
May be this would help too...
From emacs Help verbatim:
C-x M-ESC runs the command repeat-complex-command
which is an interactive compiled Lisp function in `simple.el'.
It is bound to <again>, <redo>, C-x M-:, C-x M-ESC.
(repeat-complex-command ARG)
Edit and re-evaluate last complex command, or ARGth from last.
A complex command is one which used the minibuffer.
The command is placed in the minibuffer as a Lisp form for editing.
The result is executed, repeating the command as changed.
If the command has been changed or is not the most recent previous command
it is added to the front of the command history.
You can use the minibuffer history commands M-n and M-p
to get different commands to edit and resubmit.
Personally I found Sebastian's idea useful. Here is a working version
(global-set-key "\C-r" #'(lambda () (interactive)
(eval (car command-history))))
This is old, but Google pops post this up first when I was looking to retrieve the last command I typed at the Emacs prompt. None of these answers worked for me so I decided to put in my two cents for those who might stumble upon this later on as I did. I'm using Portacle, but I found what I was looking for in here so I'm hoping it's generic enough to work with different setups. Anyway, what worked for me is using C-↑ and C-↓ to cycle through the history. Using M-p and M-n worked as well, but I prefer using the arrows since I use Bash quite a bit.
dot-mode is a way to repeat the last command(s).
From its commentary:
It emulates the vi `redo' command, repeating the
immediately preceding sequence of commands. This is done by
recording input commands which change the buffer, i.e. not motion
commands.