Questions tagged [balanced-parentheses]
The balanced-parentheses tag has no usage guidance.
54
questions
16
votes
4
answers
3k
views
How to define additional mode-specific pairs for electric-pair-mode
electric-pair-mode is a built-in mode for automatically inserting matching pairs of delimiters (parentheses, square brackets, etc.) based on the current major mode.
I know that I can define ...
11
votes
5
answers
2k
views
How to replace matching parentheses?
I write (and rewrite) a lot of mathematical formulas in LaTeX with Emacs. I frequently run into situations where I want to change a pair of matching parentheses, to improve readability. My Emacs is ...
10
votes
2
answers
223
views
What minor mode prints opening paren in the echo area?
This is a really nice feature, but it only displays when inserting a paren, not when changing to a cursor position. Is there an interactive command that I can call to display this? Can I configure it ...
9
votes
4
answers
4k
views
Automatically formatting brackets
I'm trying to create a function that places/aligns/indents curly brackets according to Allman-style formatting (for coding in C).
Generally speaking, I am fan of Smartparens' interface available to ...
9
votes
3
answers
303
views
Set region to include enclosing parentheses
Starting with the point or active region, how do I quickly (in one keystroke / command) 'expand' to include the next set of enclosing parentheses?
If I start with: (| means point)
(defn foo [x] (+ x ...
9
votes
2
answers
2k
views
How to show matching parenthesis faster?
When you type closing parenthesis (or maybe it works for other paired
symbols too), and opening parenthesis is not visible on the screen, Emacs
“jumps” to opening parenthesis to show you where it is. ...
8
votes
4
answers
907
views
How can I find surrounding parenthesis (from emacs lisp)?
Is there a way to find out the type of the surrounding parenthesis (i.e. '(', '[' or '{') around point? For example (using | to represent point)
{ abc, | df }
should return '{', and
{ abc[ | ], ...
8
votes
2
answers
4k
views
Remove parentheses around region
Is there a better alternative to this function I use to remove parens around a region? I'm looking for an Emacs builtin, or something better written, something that will remove any pairs around the ...
7
votes
2
answers
2k
views
What are the differences between autopair and smartparens?
Both autopair and smartparens provide functionality for inserting matching pairs of delimiters automatically.
How do they differ from each other in practice (if at all)? What are some use cases that ...
6
votes
2
answers
596
views
Insert parens while completing functions in company mode
If i select first option it will become
l.remove
But as the completion candidate is function type, how can i make it to
l.remove()
so that i don't have to manually type parens?
5
votes
2
answers
455
views
Remove extra braces
I have some text like this
This is a {{text}} with { { {some {extra} unneeded {
{and ugly}} braces
}}}.
Is there a way to remove the extra unneeded parenthesis so that the result is
This is a {...
4
votes
1
answer
533
views
Is there a command/package to pretty print based on parentheses?
I'm dealing with large files of output from Haskell code, most of which is debug info of stuff generating using Haskell's show.
The important thing about that is that it's a large file of things, ...
4
votes
0
answers
137
views
Add spaces between braces and content
I would like to automatically add spaces between braces and content when using emacs, for example:
std::vector<std::string> values{"content", "moreContent", "andMoreContent"};
becomes
std::...
3
votes
2
answers
618
views
automatically close type parens in C++
Does anybody know of a way or a package that can recognize < and > when occuring in template contexts and automatically writes a > either right after the < or after the selected region ...
3
votes
1
answer
78
views
How can I make `forward-sexp` handle other balanced character-pairs such as < and > or << and >>?
I am trying to find an easy and efficient way to modify the behaviour of forward-sexp to handle balanced pairs of characters not normally supported by it, such as balanced < and > and balanced &...
3
votes
1
answer
144
views
Check latex \left \right balance
I've found a function for checking parenthesis/brackets balance.
Full code is in the bottom.
I wanted to use it to check LaTeX commands like \left(/\right), \[/\] etc.
How can I modify this function ...
3
votes
0
answers
119
views
Working around preprocessor blocks
I am trying to navigate a C project that has lots of preprocessor directives like this:
#ifdef SOME_COMPILE_TIME_VARIABLE
for ( idx=0; idx<FOO; idx++ ) {
#else
for ( idx=0; idx<BAR; idx+...
3
votes
0
answers
73
views
Indent parenthesized Python expression
I have emacs set up to indent Python code like so:
foo(
bar, baz
)
That works fine. However, that style in a particular program I'm working on very often means I find myself with text like this:...
2
votes
3
answers
6k
views
How to complete brackets automatically?
I use an auto complete tool in emacs, which can complete brackets. But I want to find out that how it determines whether it should complete the bracket. For example, assuming | stands for the point. ...
2
votes
2
answers
454
views
Can't type unbalanced closing curly brace in Clojure mode
When I open a Clojure file, and I'm not using Paredit, I expect to be able to type unbalanced parentheses and brackets. I can type any of these characters: ()[]{, balanced on not. But if I try to type ...
2
votes
2
answers
160
views
Modifying AucTeX bracket indentation locally
I am currently using songs package, which via some TeX trickery uses escaped brackets to mark chords (for example \[G] is G-major, while \[a] is a-minor). This causes problems with indentation, for ...
2
votes
1
answer
96
views
Smarter smart bracket matching
It's kind of weird how un-ergonomically placed the parenthesis keys are.
I'd like a function that smartly brackets my stuff for me based on context:
If the mark is active, the region should be ...
2
votes
1
answer
611
views
Auto-completion of round bracket in Auctex
When using Auctex to type tex files, round bracket ( can't auto-complete for me. But [ and { can do. How can I fix it?
According to introduction of LaTeX-electric-left-right-brace, this variable is ...
2
votes
1
answer
1k
views
How to disable underlining of highlighted matching brackets?
I want to have no underlining on highlighted matching brackets. I've done the following to achieve that:
M-x customize-face
show-paren-match
And there I deactivated the underlining of matching ...
2
votes
1
answer
304
views
Disable mic-paren in the minibuffer (or at least in ido)
I'm replacing a buggy code that was suppose to show a matching brace in the minibuffer in case it was off-screen with the following:
(paren-activate) ;; activates mic-paren
(setq paren-match-face '...
1
vote
2
answers
90
views
how do I match brackets and parentheses in lisp code?
I started to write some elisp and have am having trouble with the brackets/parentheses. Often, I delete only one bracket/parenthesis and left the other dangling. I have trouble finding the matches.
...
1
vote
4
answers
946
views
How to delete surrounding brackets?
I'd like to be able delete the innermost brackets around the current point.
What's a good way to do this?
While the evil-surround package can do this, it needs to take a bracket type as input, so ...
1
vote
1
answer
1k
views
enable show-paren-mode in init.el
I would like to enable show-paren-mode in my configuration file init.el, which is very convenient for debugging.
As it is a minor mode as I've understood, I don't know how to proceed.
1
vote
1
answer
772
views
emacs regex to match balanced parenthesis
How can emacs lisp match balanced parenthesis? for example: "foo(bar(),hee()) out()" should be match "foo(bar(),hee())".
I try below statement but it doesn't work:
#!/usr/bin/env emacs --script
(...
1
vote
2
answers
131
views
delete-c-electric-paren deletes active region in CC mode with delete-selection-mode enabled
I've the delete-selection-mode enabled. In programming modes like Python and Lua, or in general modes like Fundamental or Text, when there's an active region, pressing ( rightly wraps the region with ...
1
vote
1
answer
46
views
How to support `<` and `>` as balanced parens without impacting ability to use them as comparison operators?
Languages like Erlang and Elixir use << >> for binaries and bit-string syntax, but they also use the classical < and > for comparison operators as well as -> and <- in list ...
1
vote
1
answer
326
views
How to find the matching bracket at a point in elisp?
What is a reliable way to find the matching balanced bracket (eg: {}, [], () in C or Python), which doesn't get confused by brackets in strings, or escaped brackets for e.g.
Example:
["Foo]" ?\] 0 [...
1
vote
1
answer
267
views
How can I skip 'Scan-error: "Unbalanced parentheses"...'?
I want to write a script in order to correct spaces inside section command in a LaTeX code, that's to say
\section{Lorem ipsum dolor
sit amet consectetuer adipiscing
elit}
should be
\section{...
1
vote
2
answers
52
views
How to capture show-paren-mode region into the kill ring?
I'm enjoying show-paren-mode using the "expression" style, which highlights a parenthesized region in a contrasting color. I'd like to define an Emacs Lisp function that could capture the region into ...
1
vote
1
answer
17
views
Counting opening and closing brace marks by specifying the mark
I have the following code to count the number of opening and closing
brackets in a selected region. How can I allow a user to select
the bracketing sign (,[,{ to count, and return two counts, one for ...
1
vote
1
answer
61
views
How to prevent smartparens slurp from slurping item separator?
I am looking into Erlang support for smartparens and would like to be able to slurp a string into the current list without including the Erlang statement termination colon in the list.
In an erlang-...
1
vote
0
answers
50
views
Test if I am inside a paired delimiter
I have been having a problem where I want an up-sexp command that treats paired delimiters like $ in LaTeX-mode just as if they were pairs of balanced parentheses. There are hacks I can use that get ...
1
vote
0
answers
107
views
Parenthesis-type-specific show-paren-mode
For unfortunate reasons, I need to write, by hand, expressions that look like the following:
.....((((((((((((((((.....+))))))))[[[[[[[[[[[[[[[[{{{{{{{{{{{{{{{{))))))))+
((((((((]]]]]]]]]]]]]]]]}}}}}}...
1
vote
1
answer
496
views
Electric/smart parentheses: allow wrapping in a nontransient way
I like smart parentheses as much as the next person, but there is one situation in which I often get frustrated. Suppose I have a TeX line reading:
Lorem ipsum dolor sit amet
Now I wish to \...
1
vote
0
answers
607
views
How can I make Spacemacs stop deleting my parentheses?
I've recently switched from emacs to spacemacs (develop branch), and I'm still getting used to the new defaults. I added smartparens to my excluded-packages in my config file, because I don't like ...
1
vote
0
answers
113
views
How does forward-list work for "<>" in c++-mode?
I am trying to understand how forward-list matches template delimiters <> in c++-mode.
forward-list in lisp.el calls scan-lists with the appropriate arguments. The documentation for scan-lists ...
1
vote
0
answers
754
views
Paredit: paredit-forward and paredit-backward don't work
I've been having trouble with navigating in paredit. When I try using C-M-f and C-M-b to go forward and backward, nothing happens. The minibuffer doesn't respond and the point doesn't move.
When I ...
0
votes
1
answer
41
views
Why does org see this source block as having "unbalanced parentheses"?
Here is a terse snippet with which you can recreate the issue, I hope:
#+begin_src sh
for x in $(for y in $(cmdA '"'); do cmdB $y; done); do cmdC $x; done
#+end_src
Here if I try to operate with ...
0
votes
1
answer
53
views
rainbow-delimiters does not properly highlight unmatched parenthesis
Would it be possible to highlight unmatched parenthesis if they are at the beginning of a function like func((((()?
Related:
How can I find missing or mismatched braces / parens in emacs?
minimal.el ...
0
votes
1
answer
48
views
Paste Inserts Extra Characters because of Electric Mode
I have this defined:
(setq electric-pair-pairs ...
0
votes
1
answer
38
views
Indicating parentheses
I have this piece that indicates an opening parenthesis by blinking it.
Currently, if I want to mark an opening parenthesis, I have to do call M-x rk-blink-matching-open each time. I would like the ...
0
votes
0
answers
23
views
What alternative exist to write specialized forward-sexp-function?
I'd like to write code that allows forward-sexp and backward-sexp commands to navigate across balanced keyword-based expressions, such as make files that use the if / fi keywords.
It's possible to ...
0
votes
1
answer
47
views
Any existing function to fix comma-separated list in parens-pair?
I am looking a way to programatically fix invalidly formatted code for programming languages that use relatively simple list expression of elements separated by commas (ie, not in C++).
For example I'...
0
votes
0
answers
115
views
Scan error: "Unbalanced parentheses" in fresh emacs installations, without config files
When I start emacs and run M-x up-list in the initial buffer (the about Emacs buffer, in fundamental mode) I get Scan error: "Unbalanced parentheses". If I move the mark to the end of the ...
0
votes
0
answers
68
views
AUCTeX pairing large parenthesis for `\left(`
I'd like to automatically close \left( with \right) in LaTeX via AUCTeX in Emacs 27. The following should work:
(add-hook 'LaTeX-mode-hook
(lambda () (set (make-local-variable 'TeX-...