From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matt Price Subject: Re: electric-pair, autopair, smartparens, etc in org-mode Date: Sun, 21 Oct 2018 12:43:25 -0400 Message-ID: References: <877eib21z0.fsf@nicolasgoaziou.fr> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="0000000000009d72db0578bfd3a7" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:60971) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gEGoV-0007LL-1C for emacs-orgmode@gnu.org; Sun, 21 Oct 2018 12:42:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gEGoT-0006gu-KC for emacs-orgmode@gnu.org; Sun, 21 Oct 2018 12:42:50 -0400 Received: from mail-it1-x12a.google.com ([2607:f8b0:4864:20::12a]:40771) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gEGoT-0006eo-9Q for emacs-orgmode@gnu.org; Sun, 21 Oct 2018 12:42:49 -0400 Received: by mail-it1-x12a.google.com with SMTP id i191-v6so9747535iti.5 for ; Sun, 21 Oct 2018 09:42:49 -0700 (PDT) In-Reply-To: <877eib21z0.fsf@nicolasgoaziou.fr> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: Org Mode --0000000000009d72db0578bfd3a7 Content-Type: text/plain; charset="UTF-8" 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 wrote: > Hello, > > Matt Price 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 > --0000000000009d72db0578bfd3a7 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
wow, I learned a wh= ole lot from your answer Nicholas, but still not quite enough to make this = work for me.=C2=A0 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<= br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 (lambda (c)
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (and (eq ?\[ c)
=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (eq major-mode 'org-mode)
=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (memq (char-before (1- (point))) '= (?\[ ?\])))))

The manual says to use advice-add instead o= f add-function for these cases, so this could be written like this instead:=

(defun mwp-org-mode-electric-inhibit (c)
=C2=A0 (and
= =C2=A0=C2=A0 (eq ?\[ c)
=C2=A0=C2=A0 (eq major-mode 'org-mode)
= =C2=A0=C2=A0 (memq (char-before (1- (point))) '(?\[ ?\]) )))

(ad= vice-add electric-pair-inhibit-predicate :before-until #'mwp-org-mode-e= lectric-inhibit)

it seems to sort of work= .=C2=A0 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 f= or this modification:

when I start a link [
<= div>go ahead and add pair to
[]
when I add a secon= d [, don't complete
[[]
this is what my code does!<= /div>

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 te= xt:
w= ith point between the final [ and ].=C2=A0
This seems like i= t needs a more complex intervention.=C2=A0

Fo= r now I've just turned off pairing of brackets entirely:

(defun mwp-org-mode-electric-inhibit (c)
=C2=A0 (and =C2=A0=C2=A0 (eq ?\[ c)
=C2=A0=C2=A0 (eq major-mode 'org-mode))

This works fine, though I'd still like the other = :-/=C2=A0

Thanks Nicholas!
On Sun, Oct 21, 2018 at 3:28 AM Nic= olas Goaziou <mail@nicolasgoaz= iou.fr> wrote:
Hello,

Matt Price <mopt= op99@gmail.com> writes:

> - electric-pair and autopair complete [[ immediately, and don't se= em 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:

=C2=A0 =C2=A0(add-function :before-until electric-pair-inhibit-predicate =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(lambda (c) =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(and (= eq ?\{ c)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 (eq major-mode 'org-mode)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 (memq (char-before (1- (point))) '(?_ ?^)))))

I guess you could do something similar to disable pairing when entering
a bracket link.

Regards,

--
Nicolas Goaziou
--0000000000009d72db0578bfd3a7--