joaotavora / autopair Goto Github PK
View Code? Open in Web Editor NEWAutomagically pair braces and quotes in emacs like TextMate
Automagically pair braces and quotes in emacs like TextMate
Hi,
The bug is hard to explained so I made a video/gif to explain: http://imgur.com/iGSln51
Without autopair this works just fine. I tested for incompatibility with other packag e and tried running with a default emacs config with only autopair loaded.
if you erase with backspace (not C-w) a region up to an autopaired symbol ( " ' [
it will insert a ^? and move stuff around.
So let's say I create a new buffer
I write in it:
"this is a test"
If I make a backward selection of this is a
(the same selection forward works) and hit backspace. instead of resulting in:
"test"
Like it does with forward selection, it does this instead:
test"�^?
Check the gif/video to get a better idea.
In it I do 3 selection
2 times backward (bug)
1 time forward (works)
Each time I erase with backspace, the bug does not reproduce with C-w
Any clue ?
See also http://code.google.com/p/autopair/issues/detail?id=45.
When I'm programming, I often find myself wrapping functions around functions - but starting with the inner parts. So whenever I add another function name and opening bracket in the beginning, autopair immediately puts in the closing bracket, which I have to delete (before adding one in the end).
In this context, skeleton-pair-like functionality would be great: Compare what's behind the cursor to a regular expression (user-adjustable), and suppress/allow pairing of brackets based on the result.
Example:
type a function call:
-> autopair has added the closing bracket - good!
wrap around another function:
-> autopair has closed the bracket prematurely - bad!
delete the bracket and add it at the end:
-> this is the end result that I wanted to have
The difference, between when I want and don't want the closing bracket added, is the context of what's behind the cursor. I can't think of a situation where a closing bracket would be immediately followed by text/numbers. Thus, it would be preferable to not insert one in such cases.
In a buffer in octave-mode, if you activate autopair-mode, '(' or '[' often let the Emacs freeze.
I use Emacs 24.2.1 in Ubuntu 11.4, with octave-mode shipped with Emacs itself, and the latest git version of autopair.el
Here's a post by someone who has the same problem: http://code.google.com/p/autopair/issues/detail?id=57
Discovered this by mistake when editing a scss file. Steps to reproduce:
emacs -Q
C-x <autopair.el location>
M-x eval-buffer
C-x b <*scratch*>
C-x h <delete>
M-x css-mode
M-x autopair-mode
Then type a ;
, C-b
over it, and attempt to type a (
. On Emacs 24.2.9 I get a complete lock-up.
I've had a look at the autopair.el source, but I'm not familiar enough with it to see the problem ...
Under ada-mode, when using the command autopair-newline
(binded to RET), emacs raises a "Variable binding depth exceeds max-specpdl-size" error.
If I have (add-hook 'prog-mode-hook 'autopair-mode) in ~/.emacs, then
when I press C-M-n or C-M-f, I see the following errors.
forward-sexp: Scan error: "Containing expression ends prematurely", 575, 576 [4 times]
forward-sexp: Scan error: "Containing expression ends prematurely", 548, 548
forward-sexp: Scan error: "Containing expression ends prematurely", 575, 576
forward-list: Scan error: "Containing expression ends prematurely", 575, 576 [3 times]
forward-list: Scan error: "Containing expression ends prematurely", 548, 548
If I type "M-x autopair-mode RET" in a buffer instead of having (add-hook 'prog-mode-hook 'autopair-mode) in ~/.emacs, forward-sexp and forward-list don't give errors.
What's wrong with my configuration?
The new ruby-mode is using SMIE for indentation and sexp navigation.
In certain conditions autopair does not insert the closing paren in this mode.
I'm typing (
at the position denoted by |
.
This:
def qux
@foo = {}
@bar.tee|
end
results in @bar.tee(
, but this:
def qux
@bar.tee|
end
results in @bar.tee()
, as expected.
I'm seeing this warning, when in multi-web-mode and backspacing/re-typing a closing paren:
Making autopair-emulation-alist buffer-local while locally let-bound!
You do have to install multi-web-mode to see this, alas, but the error does seem to point to auto-pair. Here's how I reproduce it:
Set up multi-web-mode, this is in my .emacs:
(require 'multi-web-mode)
(setq mweb-default-major-mode 'html-mode)
(setq mweb-tags '((php-mode "<\\?php\\|<\\? \\|<\\?=" "\\?>")
(js-mode "<script[^>]*>" "</script>")
(css-mode "<style[^>]*>" "</style>")))
(setq mweb-filename-extensions '("php" "htm" "html" "ctp" "phtml" "php4" "php5"))
(multi-web-global-mode 1)
Open an empty buffer and type:
<?php foo()
The M-x autopair-mode, multi-web-mode
Turn off any other minor modes that may have come up
Delete the final closing paren, and retype it
I now see:
Making autopair-emulation-alist buffer-local while locally let-bound! [2 times]
call-interactively: Wrong type argument: listp, set-from-style
Autopair seems to inhibit eldoc somehow. The arguments don't appear as soon as i type the "(". Sometimes i have to navigate to the outside and return to see the function arguments displayed by eldoc. Smartparens doesn't present this particular problem.
sorry, hit return not tab
Hi,
After an update today, I can't insert a parenthesis inside a paired parenthesis.
It seems that since last commit (3693ad6) autopair have used paren.el's show-paren-data-function, but that symbol is not defined in 24.3's paren.el... It is defined in trunk though.
Is there a way to work around it?
By the way, I tried to defvar show-paren-data-function as show-data-funtion in ~/.emacs, but strangely emacs told me it is undefined, too, event though I stated (require 'paren) explicitly before that defvar. I'm confused.
-------------------NEW-----------------
Well, (defvar show-paren-data-function 'show-data-funtion) now works, and I don't know why.
I take the code of show-paren--default from trunk and it works.
But still I don't think it's a good idea to use show-paren-data-function before it go into the stable tree.
There are plenty of scripts to do that, so google says.
If I select a b
in a lisp buffer and press (
, it will replace the selection with (a b)
, if only one of paredit mode and autopair mode is enabled. If both are enabled, it gets replaced with (a b))
.
versions:
paredit 20130722.1324
autopair 20121123.1829
GNU Emacs 24.3.1
Why this should be considered a bug on autopair side: playing nice with other packages is one of autopair's goal.
this extension is fantastic, thank you!
I usually find that when I type an opening parenthesis that I don't want to be matched, it is usually when there is some non-whitespace text to the right of the point.
Can you please consider adding this functionality as a feature? If not, I'm sure I could write a little wrapper that investigates following-char
http://www.gnu.org/software/emacs/manual/html_node/elisp/Near-Point.html
I'm using the latest autopair with Emacs 24.3.1 on Ubuntu Saucy. Whenever I open a python file and try to make an edit, autopair goes into some kind of loop and I get an error
(error "Lisp nesting exceeds `max-lisp-eval-depth'")
If I run the debugger, the backtrace is just these three lines repeated hundreds of times:
autopair-fallback("^M")
autopair-newline()
call-interactively(autopair-newline)
Open a LaTeX buffer with AucTeX activated. If you type (
, then autopair automatically gives ()
with the cursor in the middle. If you type )
, then this gives ()
as expected.
However, if you do the same thing with curly braces, this gives {}}
: the closing brace is repeated.
Note that it works fine, e.g. with the BibTeX mode.
This is one of the features in the similar plugin for Vim.
"Hello, world!|"
Now I don't want to type "
to skip it. I just want some generic key binding that will do that for me regardless of whether it is "
, or )
, or }
, you get the point. So I just tap the key and I'm outside:
"Hello, world!"|
Is this feature available in autopair
? If not, how tough for you would it be to add it?
Thanks for a high-quality plugin.
Matching parens in a python takes around 5-10 seconds in a moderately-sized python for me since the most recent revision. Earlier revisions work without any problems. This happens even in a clean .emacs file.
Here are results from profiling with elp:
Function Name Call Count Elapsed Time Average Time
autopair-insert-opening 1 7.250252 7.250252
autopair-pair-p 1 7.250151 7.250151
autopair-up-list 1 7.250044 7.250044
autopair-post-command-handler 21 0.1020060000 0.0048574285
autopair-default-handle-action 1 0.101946 0.101946
autopair-blink 1 0.101904 0.101904
autopair-global-mode-enable-in-buffers 8 0.0022830000 0.0002853750
autopair-set-emulation-bindings 6 0.002097 0.0003495
autopair-on 3 0.00112 0.0003733333
autopair-mode 3 0.001103 0.0003676666
autopair-fallback 3 0.000185 6.166...e-05
autopair-newline 2 0.000165 8.25e-05
autopair-syntax-ppss 1 6.1e-05 6.1e-05
autopair-original-binding 6 5.299...e-05 8.833...e-06
autopair-global-mode-check-buffers 2 3.700...e-05 1.850...e-05
autopair-find-pair 3 2.100...e-05 7.000...e-06
autopair-global-mode-cmhh 3 9.999...e-06 3.333...e-06
autopair-calculate-inserted 3 4e-06 1.333...e-06
autopair-exception-p 4 3e-06 7.5e-07
autopair-python-triple-quote-action 1 3e-06 3e-06
autopair-calculate-wrap-action 3 2e-06 6.666...e-07
autopair-escaped-p 1 1e-06 1e-06
When writing code, I come across autocomplete suggestions and when I press enter autocomplete completes my words with the suggestions.
But ever since I started using autopair.el, the enter merely goes to the other line in the same situations. I have to use tab.
I went thorough the autopair.el to see if I could change something and get this fixed, but was beyond me.
Did someone happen to find the same a problem and come up with a solution.
'single quote' support would be awesome!
In Org, I mostly want autopair's default pairing for <
to work, except when it is the first character in a line (column 0), when I want plain self-insert-command. Org has a template insertion feature triggered by <s
followed by TAB
at the beginning of a line.
I may be missing something but I can't see how to achieve this with autopair's existing features.
Not a huge problem, since C-d removes the paired >
, but annoying.
with the autopair minor-mode enabled as well as the ac-mode, when I want to write "print" with the "pr" already typed, the auto-complete will show the "int" with underline to prompt me to hit the Return to complete the word. However, with the autopair-mode enabled, when I hit the Return the"int" with underline is gone and the cursor goes to the begin of the next line. sorry for the poor English.
this is duplicated in the auto-complete/auto-complete#43
When i remove some character or region in .tpl:
autopair--calculate-wrap-action: Wrong type argument: characterp, 134217828
This is the reliable way for me to reproduce this error, in some more simple states it will also start returning errors. Empty file in js2-mode:
function () {
for [CURSORHERE]
};
With the cursor at [CURSORHERE]
, open a parenthesis. The function autopair-pair-p
returns with a (args-out-of-range 25 49)
error created by forward-sexp
. The first error handler tries a string compare and craps out with Wrong type argument: stringp, 25.
I have a rather large python file (~ 5000 lines consisting of Django models). autopair crawls when trying to insert new quotes. The UI freezes for 10-15 seconds and then inserts the pair of quotes.
The closer to the top of the file I am, the longer the the UI blocks. At the bottom of the file, their is no perceptible delay.
I'm not familiar with the autopair source -- but it seems as if it may be scanning to the end of the file before inserting new quotes. Might be related to issue #36.
It only seems to happen with quotes ("
and '
) -- parens, braces, etc work just fine.
It would be handy for Python programmers if autopair supported a flag to enable triple quoted strings. Here is how quoting and deletion should work:
| --> "|"
"|" --> """|"""
"""|""" --> "|"
"|" --> |
If I have time next week I can hack this up if you would be willing to accept a patch.
In nXML mode
it shows
autopair-insert-or-skip-quote: Wrong type argument: integer-or-marker-p, nil
Hi capitaomorte,
I got a "Warning: reference to free variable `autopair-mode'" message in the Compile-Log buffer while I recover from desktop seesion.
Initially reported by: [email protected]
What steps will reproduce the problem?
What is the expected output? What do you see instead?
The point (cursor) should move to a new corner in the marked rectangle, instead autopair-newline deletes the marked content
What version of the product are you using? On what operating system?
Newest autopair v.0.4 rev 42 on Ubuntu 12.04 with emacs 24.3.1
Hi, thanks for autpair - still works better/more reliably than electric-pair in my experience :)
Hoping for pointers of how to achieve the following (if it's not currently possible, any pointers as to what elisp funs I should be looking into for where to patch?)
Right after inserting eg. a () pair, I'd like a space to insert a pair of spaces - sort of like currently happens with newlines. Eg. sometimes you want to type function(arg)
but sometimes that's not very readable and you want to type complex_func_name( lots, of, spaced, args )
. Once I've achieved this then the ignore whitespace option makes the closing ) easy.
Any thoughts?
This is the same issue as Issue 47 on the old google code tracker.
Expect: digit to be entered once
Actual: digit is entered twice
Emacs version 24.3.1
This workaround fixes it:
(add-hook 'calc-mode-hook #'(lambda () (autopair-global-mode -1)))
Note, that autopair-global-mode has to be unset in the hook, not autopair-mode (as recommended in the docs)
This must be a recent change, because it was fine a few weeks ago. I verified by removing autopair and everything works. Details:
I'm using autopair 20131009.1902 from MELPA, and now keys like backspace
and enter
(which are bound to autopair
keys) in isearch-mode-map
break expected behavior.
For example, C-s hellp
. Oops. backspace
(so I can type o
) now actually deletes the character under my point (not in the isearch
minibuffer). Enter is the same, it actually inserts a return in my buffer instead of leaving isearch
like it usually does.
following code is not work in Emacs 24.3 (emacs -Q)
(add-hook 'ruby-mode-hook
#'(lambda ()
(push '(?` . ?') (cl-getf autopair-extra-pairs :comment))
(push '(?` . ?') (cl-getf autopair-extra-pairs :string))
))
But, those code work well for emacs lisp mode.
Thanks.
First things first - I love the behavior of this plugin. It's exactly what I wanted.
Yet, I have two issues:
first, is the electric-pair-mode in emacs 24 I just can't seem to automatically disable.
I tried (electric-pair-mode nil) and (setq electric-pair-mode nil) and they both failed.
Any ideas?
Second is deletion behavior - if I have autowrap on, I kind of expect being able to toggle the pairs. pressing C-space, for example, to remove the pairs completely, or pressing Space-' to change my double quotes (") to single quotes.
Even when I'm next to a pair in either side, deleting it keeps the other one intact - only when there is no text in between does it delete its pair.
Triggered by this http://stackoverflow.com/questions/13549419/minor-tweak-autopair-emacs I tried to make that change in autopair but could only come up with hacks.
One possibility would be to offer a new choice variable and cond on it again or simply call some user defined function with the region as arguments after a wrap action.
I am using autopair with js3mode
When I type the following, I don't get what I expect:
What I type:
it('should just work')
that is fine. but then when I add the callback function argument:
it('should just work',function()
notice, I've only typed the opening parenthesis after function, and it did not echo the closing parenthesis. Then, when I finish defining the function like so, and type the closing parenthesis, I get:
it('should just work',function(done){
}
The second parenthesis is gone, and should be outside of the closing brace.
This is just a conflict of some sort with js3 mode, as far as I can tell. When I type the same stuff in, say, a markdown file, I get:
it('should just work',function(done){
})
Again, notice the second parenthesis isn't gone, but is outside of the brace.
Thanks
Having characters like @ # ,
'` (basically any character that has some special meaning in elisp) presented in the elisp file messes up autopair.
Simplest case:
open new buffer with emacs-lisp-mode
type ((
results in (())
- which is fine
type '((
results in '(()
- which is bad.
but if escaped - \'((
, it results in \'(())
- which is fine again.
Switch '
with any of the @ # ,
'` and it behaves the same way.
Reproduced with emacs -Q
and init file
(add-to-list 'load-path "/path/to/autopair")
(require 'autopair)
(autopair-global-mode)
Windows 8.1
GNU Emacs 24.3.1 (i386-mingw-nt6.2.9200) of 2013-03-18 on MARVIN
autopair revision 029bdf0
Turn on delete-selection-mode
and autopair-autowrap
, press key with selection does not delete the selection.
It would be nice to access autopair's preferences via M-x customize. I would be willing to do most of the work in converting most of the variables meant for user customization to be declared with defcustom. Is this something you'd be interested in merging if I did the work?
I want to change the color of the different levels of pairs (4). But I cannot find the associated face.
GNU Emacs 24.3.50.1
I''ve tried to use autopair 0.3 from package-install, it worked ok, but in C-mode. Ive decided to download this latest version and get message:
custom-declare-group: Wrong type argument: symbolp
My fix is to remove '
symbol from
(defgroup 'autopair nil
Maybe i do smth wrong, i'm very new to Emacs
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.