[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] electric-pair, autopair, smartparens, etc in org-mode
From: |
Roland Everaert |
Subject: |
Re: [O] electric-pair, autopair, smartparens, etc in org-mode |
Date: |
Tue, 23 Oct 2018 09:58:08 +0200 |
User-agent: |
mu4e 1.1.0; emacs 26.1 |
Hi,
I use the following configuration:
;;;;;;;;;;;;;;;; parenthèses, accolades et brackets ;;;;;;
(setq skeleton-pair t)
(global-set-key "[" 'skeleton-pair-insert-maybe)
(global-set-key "{" 'skeleton-pair-insert-maybe)
(global-set-key "(" 'skeleton-pair-insert-maybe)
(global-set-key "\"" 'skeleton-pair-insert-maybe)
(global-set-key "'" 'skeleton-pair-insert-maybe)
This will only close the defined characters.
Hope this will help.
Roland.
Matt Price writes:
> wow, I learned a whole lot from your answer Nicholas, but still not quite
> enough to make this work for me. After some puzzling over the syntax for
> character values, I believe that what I want should be something like this:
>
> (add-function :before-until electric-pair-inhibit-predicate
> (lambda (c)
> (and (eq ?\[ c)
> (eq major-mode 'org-mode)
> (memq (char-before (1- (point))) '(?\[ ?\])))))
>
> The manual says to use advice-add instead of add-function for these cases,
> so this could be written like this instead:
>
> (defun mwp-org-mode-electric-inhibit (c)
> (and
> (eq ?\[ c)
> (eq major-mode 'org-mode)
> (memq (char-before (1- (point))) '(?\[ ?\]) )))
>
> (advice-add electric-pair-inhibit-predicate :before-until
> #'mwp-org-mode-electric-inhibit)
>
> it seems to sort of work. That is, the code is effective, but it doesn't
> do what I want, so I had to think about the desired behaviour, which is
> maybe too complex for this modification:
>
> when I start a link [
> go ahead and add pair to
> []
> when I add a second [, don't complete
> [[]
> this is what my code does!
>
> but what I really want is, when I finish adding a link reference, somehow
> allow me to stay inside the link to add the link text:
> [[https://google.com]] --> [[https://google.com][]]
> with point between the final [ and ].
> This seems like it needs a more complex intervention.
>
> For now I've just turned off pairing of brackets entirely:
>
> (defun mwp-org-mode-electric-inhibit (c)
> (and
> (eq ?\[ c)
> (eq major-mode 'org-mode))
>
> This works fine, though I'd still like the other :-/
>
> Thanks Nicholas!
> On Sun, Oct 21, 2018 at 3:28 AM Nicolas Goaziou <address@hidden>
> wrote:
>
>> Hello,
>>
>> Matt Price <address@hidden> writes:
>>
>> > - electric-pair and autopair complete [[ immediately, and don't seem to
>> > allow me to skip past the closing brackets, so if I try to type [[
>> > https://link.to.somewhere][link text]] I end up with
>> > [[link.to.somewhere]][link-text] .
>>
>> I use C-c C-l to insert links with description. However, electric
>> pairing does get in the way when writing sub/superscript. I use the
>> following snippet to work around the issue:
>>
>> (add-function :before-until electric-pair-inhibit-predicate
>> (lambda (c)
>> (and (eq ?\{ c)
>> (eq major-mode 'org-mode)
>> (memq (char-before (1- (point))) '(?_ ?^)))))
>>
>> I guess you could do something similar to disable pairing when entering
>> a bracket link.
>>
>> Regards,
>>
>> --
>> Nicolas Goaziou
>>
--
Luke, use the FOSS
Sent from Emacs
- [O] electric-pair, autopair, smartparens, etc in org-mode, Matt Price, 2018/10/20
- Re: [O] electric-pair, autopair, smartparens, etc in org-mode, Nicolas Goaziou, 2018/10/21
- Re: [O] electric-pair, autopair, smartparens, etc in org-mode, Matt Price, 2018/10/21
- Re: [O] electric-pair, autopair, smartparens, etc in org-mode,
Roland Everaert <=
- Re: [O] electric-pair, autopair, smartparens, etc in org-mode, stardiviner, 2018/10/23
- Re: [O] electric-pair, autopair, smartparens, etc in org-mode, Eric S Fraga, 2018/10/23
- Re: [O] electric-pair, autopair, smartparens, etc in org-mode, Matt Price, 2018/10/24
- Re: [O] electric-pair, autopair, smartparens, etc in org-mode, Eric S Fraga, 2018/10/24
- Re: [O] electric-pair, autopair, smartparens, etc in org-mode, Roland Everaert, 2018/10/24
- Re: [O] electric-pair, autopair, smartparens, etc in org-mode, Eric S Fraga, 2018/10/24
- Re: [O] electric-pair, autopair, smartparens, etc in org-mode, Tim Cross, 2018/10/24
- Re: [O] electric-pair, autopair, smartparens, etc in org-mode, Eric S Fraga, 2018/10/25
- Re: [O] electric-pair, autopair, smartparens, etc in org-mode, Samuel Wales, 2018/10/25
- Re: [O] electric-pair, autopair, smartparens, etc in org-mode, Samuel Wales, 2018/10/25