Paredit doesn't remove right paren on paredit-backward-kill-word - emacs

The buffer is "(|)". On Alt+Backspace which sends paredit-backward-kill-word, it only removes the left paren and leaves the buffer as "|)".
I thought it was a bug in Paredit or Emacs. But Alt+Backspace works exactly the same way in Clojure editor in IntelliJ IDEA. It made me think - is it a feature in Paredit? What's the point?

Have you tried using Alt+d. Find paredit cheatsheet

Related

Traverse to matching parens in Lispworks

Is this possible? I haven't been able to find out how in the help or manuals.
C-M-Left and C-M-Right should jump the cursor to the previous and next SEXP in the LispWorks editor which really is an old version of emacs.

Let Emacs move the cursor off-screen

Is it possible to let Emacs have the cursor be moved off-screen, like most GUI text editors work? This is one of the biggest things that bothers me when I use Emacs over any GUI editor. When I scroll down, the cursor is "pushed forward" by the top of the buffer.
I had previously thought that this was completely impossible, because this is hard-wired into the architecture of Emacs, but then I saw multiple-cursors, which does exactly this for the secondary cursors (assuming you prevent the scrolling functions from acting on the secondary cursors). Is it maybe possible to use multiple-cursors to have the main cursor in some hidden buffer, and the effective cursor being what I actually edit with? Or maybe some other clever trick? Or maybe my Googling has failed me and this is really already possible without any magic?
There is a new package available on GNU ELPA called scroll-restore that attempts to remedy this problem. So far, I have encountered a few bugs, but the package seems to work as-advertised for the most part.
You can test it out by installing it with
M-x package-install RET scroll-restore RET
After the package is installed, you can enable the minor mode with
M-x scroll-restore-mode
Personally, I am binding it to the Scroll Lock key because it seems so incredibly apropos! This is what I am adding to my init file:
(require 'scroll-restore)
(scroll-restore-mode 1)
;; Allow scroll-restore to modify the cursor face
(setq scroll-restore-handle-cursor t)
;; Make the cursor invisible while POINT is off-screen
(setq scroll-restore-cursor-type nil)
;; Jump back to the original cursor position after scrolling
(setq scroll-restore-jump-back t)
;; Toggle scroll-restore-mode with the Scroll Lock key
(global-set-key (kbd "<Scroll_Lock>") 'scroll-restore-mode)
This is a direct copy of an answer posted here: https://emacs.stackexchange.com/a/2273/93
Strictly, speaking you can't move the cursor offscreen, because the underlying C code won't let you do it.
This said, I suspect that your problem can be fixed. Basically, there are 2 aspects:
you don't like the way things look when "the cursor is pushed forward". You could work around that by (temporarily) making the cursor invisible.
you want to "jump back" to the pre-scrolling position as soon as you issue a non-scrolling command. There's probably some package out there that does it for you, but you can do it yourself with some pre-command-hook hacking.
BTW, I'd welcome patches in Emacs which provide some of that functionality. I hate the "auto jump-back" behavior of other editors, but it would be good to record the "pre-scroll" position and then offer a way to jump back to it.
Judging by the context and description of your problem, it looks like you want to browse the buffer while preserving your place of editing. There are at least two tricks for that purpose: marks/registers and splitting in two windows.
https://stackoverflow.com/a/3777598/308668 describes the Emacs' registers that act like Vim's marks. You can check in your place in the file with keying C-x r SPC a (a being a letter of your choice) and you can always come back with C-x r j a.
Some sort of automation is achieved by an external script (goto-last-change.el), described here: https://superuser.com/a/184402/49046.
Alternatively, split the window in two with C-x 2. The newly split windows both show the same location and you can use the other to explore. C-x 0 closes a window when you're done.

ajax-like command helper for EMACS?

I am new to Emacs. I find it is powerful and very convenient IF one can master its set of commands. I also believe anyone can do this with patience, and the eagerness to learn and USE the software. However it will be much nicer for beginners, and seasonal users to have some command helper plugin that do following thing:
When the user start typing any CONTROL or META, COMMAND, or any special keys, a "ajax-like" or "smart search" window appear below or in the minibuffer showing help text like, for example: If I hold "CONTROL", command helper windows shows:
C-p Up one line
C-n Down one line
C-f Forward one character
C-b Backward one character
C-a Beginning of line
C-e End of line
C-x ...
Then if I continue to type "x" while holding "CONTROL", the window will update and show something like:
C-x C-a add-mode-abbrev
C-x C-b list-buffers
C-x C-c save-buffers-kill-emacs
C-x C-d list-directory
C-x C-e eval-last-sexp
C-x C-f find-file
C-x C-h inverse-add-mode-abbrev
C-x TAB indent-rigidly
C-x C-l downcase-region
C-x C-n set-goal-column
C-x C-o delete-blank-lines
I have tried googling it, but it doesn't seem exist yet. So I guess this is more a feature request for EMACS rather then a question. But it is great if somebody can write a plugin/module to do this.
I do not believe this is out there, but I also believe that it is not really needed. It would just clutter the screen, though, maybe for a rookie it might be indeed useful.
For now, you might consider printing a cheatsheet.
Do not lose hope, I learned it without any sort of help, the key is indeed to just use it often.
Also, there is quite a good logic behind it all, so if you read up the structure in a cheatsheet or anywhere else, then it might help you "guess" what is the right key combo sooner than later.
EDIT: I actually myself asked a similar question, at least the same functionality was required. I accepted an answer which apparently mentions that Icicles offers this functionality.
Also, one advise is that after you type the prefix key, e.g. C-c, typing C-h afterwards will show you the possible completions.
This leads me to the following:
I believe we could use code like:
"If last key is a prefix key, run C-h*, switch back to previous buffer and rehit the last prefix key"
*this is a general method, working even for my own poorly designed minor mode
I also don't know an existing package that would do that, but here's a couple of tips.
To get an overview of all available bindings, press C-h b. The displayed buffer looks fairly raw, because it includes all ways used to enter special characters (and they are usually at the top), but you can search it with C-s if you remember at least a part of the command name.
If you know the prefix (e.g. C-x) but don't remember what comes next, you can follow it with C-h instead (type C-x C-h). That will bring up a similar buffer that only contains bindings that start with the same prefix. It's one of the more obscure features, I think.
Speaking of "if I hold Ctrl", though, showing hints when you've just pressed Ctrl and nothing else if currently impossible to implement at the Lisp level. That would require some lower-level changes.
There are too many keybindings in emacs for this to be practically useful.
I agree with the other responses and just wanted to add that I found the built-in tutorial very useful for getting past the basics. You can reach the tutorial with C-h t.
You'll probably end up changing several of the default bindings, but learning them will help you find your way around new modes (assuming that they work in an "emacsy" way).
I come back to this be cause I found a perfect solution and can't live without it: The emacs-helm and which-key

How to delete extra parens in Paredit mode?

I'm using Paredit in Emacs to edit Lisp code. How do I delete an extra pair of parens that I accidentally inserted? Paredit does not allow this without extra commands.
((square 5)) into (square 5)
This is called paredit-splice-sexp, keybinding is M-s.
Take a look at the paredit cheat sheet here.
Read up on barfage and slurpage.
You can also installed "paredit-menu.el" which provides a menu of actions, with tooltips that show you their effects.
Paredit occasionally gets you into a situation when the easiest thing to do is to turn it off, fix everything and turn it on again. However, it is worth the effort.
If I realized accidental extra parens right after inserting those extra parens, I would invoke the undo command. If I saw the extra parens much later, then there are paredit commands for fixing it as other answers specified, but if I did not know those commands, then I would have put point somewhere within the inner form, and then typed the following, provided that CUA mode is on.
C-M-u C-M-SPC C-x <timeout> <left> C-M-SPC C-v
The paredit wont let us deleting parens while there is any elements inside. My trick is to cut the the right code and paste it to other place adjacent. It will leave the extra parens empty, then now I can delete it. Actually the right way is using M-s to reindent it. Conversely we can insert single paren using C-q ( or C-q }.

Scheme editing in Emacs - modes and keyboard layout

Recently I started using Emacs as my Scheme (Lisp) editor. I'm thinking what extensions should I use in order to achieve the best performance. Currently I'm using Paredit and it helps a lot. I know that there are numerous Scheme extensions for Emacs: Geiser, Quack to name the two that seem very popular, and EmacsWiki lists many more. Which of these have you guys used and which ones do you find the best? At the moment my biggest problem is lack of parentheses colouring, which makes it vary hard to pair them visually - indentations are not enough when you have a line of code ending with ))))))))
I'm also thinking how could I improve the keyboard layout of Emacs in order to do better in Scheme editing? I've found some good advice on CLiki. I swapped [] with () on the keyboard and that's helpful. I'm also considering swapping Alt and Ctrl keys.
Do you have any other tips and suggestions that make it easier to edit Scheme in Emacs?
I've found rainbow delimiters mode really helpful for highlighting different levels of parentheses.
Among other modes that help me write lisp are hideshow mode for folding of sexps, slime which is primarily for Common Lisp but I use it's indentation capabilities in scheme too, low-contrast color theme called solarized with which my eyes don't fatigue any more and heavily mutated vim mode which permits me to keep my keybindings manageable through editing modes.
I use show-paren-mode, a minor mode, with these in my .emacs:
(show-paren-mode t)
(setq show-paren-delay 0)
(setq show-paren-style 'expression) ; alternatives are 'parenthesis' and 'mixed'
Relevant faces to modify are show-paren-match and show-paren-mismatch.
It only highlights a sexp when point is immediately before or after it, but I like that it's not so in-your-face.
I use autopair to get parenthesis right, show-paren-mode to see the end and beginning of s-expressions and expand-region to mark s-expression (It works on a lot more than that).
I think as you keep playing with paredit you may see less and less need for parenthesis coloring. For example, type ')' within any sexp, and the opening and closing parens will be momentarily highlighted; then point will move to the end of the sexp. Being able to navigate the nested sexp structure easily - for example, C-M-u and C-M-d to navigate up and down one paren level - also takes away some of the need to visually pair parenthesis.