From: Juri Linkov <juri@linkov.net>
To: Pedro Andres Aranda Gutierrez <paaguti@gmail.com>
Cc: emacs-devel <emacs-devel@gnu.org>
Subject: Re: Proposal: make insert-pair-alist buffer local
Date: Thu, 23 Dec 2021 19:12:54 +0200 [thread overview]
Message-ID: <86o857e6i1.fsf@mail.linkov.net> (raw)
In-Reply-To: <CAO48Bk_QW0yRf-YZBbZ6VZQ-cQkx91nc6DurcUYYbRUk0_EeFQ@mail.gmail.com> (Pedro Andres Aranda Gutierrez's message of "Thu, 23 Dec 2021 13:11:34 +0100")
> This is a "don't shoot the pianist" (cf. cite below) sort of idea I have
> had while trying to rationalize my .emacs.d:
>
> If insert-pair-alist was buffer-local, we could have different auto-pairs
> for different modes:
> e.g. //,**, etc. in org-mode
>
> Am I too wrong in this?
In my experience, the value of insert-pair-alist could depend not only
on mode, but also on more language context around point, so for example,
to insert a pair of quotes, insert-pair-alist should insert “”
in some languages, and «» in other languages, so the logic can be
more complex than just setting a buffer-local value, and a more
flexible solution would be to let-bind insert-pair-alist, e.g.:
#+begin_src emacs-lisp
(defun use-fancy-quotes-p ()
(and (memq buffer-file-coding-system '(utf-8 utf-8-unix utf-8-emacs-unix))
(or (and comment-start (nth 4 (syntax-ppss)))
(and (derived-mode-p 'text-mode)
(not (and (derived-mode-p 'org-mode)
(consp (get-text-property (point) 'face))
(memq 'org-block (get-text-property (point) 'face))))
(not (derived-mode-p 'vc-git-log-edit-mode))
(not (derived-mode-p 'sgml-mode))
(not (derived-mode-p 'yaml-mode)))
(derived-mode-p 'fundamental-mode))))
(define-key esc-map "\""
(lambda ()
(interactive)
(let ((insert-pair-alist
(cons
(if (use-fancy-quotes-p)
(if (and (not (eobp)) (eq (aref char-script-table (char-after)) 'cyrillic))
'(?\" ?\« ?\»)
'(?\" ?\“ ?\”))
'(?\" ?\" ?\"))
insert-pair-alist)))
(call-interactively 'insert-pair))))
(define-key esc-map "'"
(lambda ()
(interactive)
(let ((insert-pair-alist
(cons
(if (use-fancy-quotes-p)
'(?\' ?\‘ ?\’)
'(?\' ?\' ?\'))
insert-pair-alist)))
(call-interactively 'insert-pair))))
(define-key esc-map "[" 'insert-pair)
(define-key esc-map "{" 'insert-pair)
#+end_src
next prev parent reply other threads:[~2021-12-23 17:12 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-23 12:11 Proposal: make insert-pair-alist buffer local Pedro Andres Aranda Gutierrez
2021-12-23 12:41 ` Po Lu
2021-12-23 13:11 ` Óscar Fuentes
2021-12-23 13:28 ` Po Lu
2021-12-23 17:12 ` Juri Linkov [this message]
2021-12-23 18:15 ` Eli Zaretskii
2021-12-23 19:33 ` Stefan Monnier
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=86o857e6i1.fsf@mail.linkov.net \
--to=juri@linkov.net \
--cc=emacs-devel@gnu.org \
--cc=paaguti@gmail.com \
/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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.