emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Matt Price <moptop99@gmail.com>
To: Org Mode <emacs-orgmode@gnu.org>
Subject: Re: electric-pair, autopair, smartparens, etc in org-mode
Date: Sun, 21 Oct 2018 12:43:25 -0400	[thread overview]
Message-ID: <CAN_Dec9pFfmkcRQEvdcUqtnkiGzGFYMHSRkfY515QE4WO+Zcgw@mail.gmail.com> (raw)
In-Reply-To: <877eib21z0.fsf@nicolasgoaziou.fr>

[-- Attachment #1: Type: text/plain, Size: 2579 bytes --]

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 <mail@nicolasgoaziou.fr>
wrote:

> Hello,
>
> Matt Price <moptop99@gmail.com> 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
>

[-- Attachment #2: Type: text/html, Size: 3780 bytes --]

  reply	other threads:[~2018-10-21 16:42 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-21  0:36 electric-pair, autopair, smartparens, etc in org-mode Matt Price
2018-10-21  7:28 ` Nicolas Goaziou
2018-10-21 16:43   ` Matt Price [this message]
2018-10-23  7:58     ` Roland Everaert
2018-10-23 11:48       ` stardiviner
2018-10-23 13:07         ` Eric S Fraga
2018-10-24 13:12           ` Matt Price
2018-10-24 14:15             ` Eric S Fraga
2018-10-24 10:38         ` Roland Everaert
2018-10-24 10:45           ` Eric S Fraga
2018-10-24 21:24             ` Tim Cross
2018-10-25 15:07               ` Eric S Fraga
2018-10-25 22:57                 ` Samuel Wales
2018-10-25 22:59                   ` Samuel Wales
2018-10-26  9:23                   ` Eric S Fraga
2018-10-26 21:45                   ` Tim Cross

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAN_Dec9pFfmkcRQEvdcUqtnkiGzGFYMHSRkfY515QE4WO+Zcgw@mail.gmail.com \
    --to=moptop99@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).