unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Proposal: make insert-pair-alist buffer local
@ 2021-12-23 12:11 Pedro Andres Aranda Gutierrez
  2021-12-23 12:41 ` Po Lu
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Pedro Andres Aranda Gutierrez @ 2021-12-23 12:11 UTC (permalink / raw)
  To: emacs-devel

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

Hi

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?

Best, /PA

-- 
Fragen sind nicht da um beantwortet zu werden,
Fragen sind da um gestellt zu werden
Georg Kreisler

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Proposal: make insert-pair-alist buffer local
  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 17:12 ` Juri Linkov
  2021-12-23 19:33 ` Stefan Monnier
  2 siblings, 1 reply; 7+ messages in thread
From: Po Lu @ 2021-12-23 12:41 UTC (permalink / raw)
  To: Pedro Andres Aranda Gutierrez; +Cc: emacs-devel

Pedro Andres Aranda Gutierrez <paaguti@gmail.com> writes:

> Hi
>
> 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

You can just set it as a buffer-local variable, like so:

  (setq-local insert-pair-alist ...

Also look into `make-local-variable' and friends.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Proposal: make insert-pair-alist buffer local
  2021-12-23 12:41 ` Po Lu
@ 2021-12-23 13:11   ` Óscar Fuentes
  2021-12-23 13:28     ` Po Lu
  0 siblings, 1 reply; 7+ messages in thread
From: Óscar Fuentes @ 2021-12-23 13:11 UTC (permalink / raw)
  To: emacs-devel

Po Lu <luangruo@yahoo.com> writes:

> Pedro Andres Aranda Gutierrez <paaguti@gmail.com> writes:
>
>> Hi
>>
>> 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
>
> You can just set it as a buffer-local variable, like so:
>
>   (setq-local insert-pair-alist ...
>
> Also look into `make-local-variable' and friends.

I think he is not asking about how to solve his particular problem, but
suggesting a possible improvement to Emacs.




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Proposal: make insert-pair-alist buffer local
  2021-12-23 13:11   ` Óscar Fuentes
@ 2021-12-23 13:28     ` Po Lu
  0 siblings, 0 replies; 7+ messages in thread
From: Po Lu @ 2021-12-23 13:28 UTC (permalink / raw)
  To: Óscar Fuentes; +Cc: emacs-devel

Óscar Fuentes <ofv@wanadoo.es> writes:

>>> If insert-pair-alist was buffer-local, we could have different
>>> auto-pairs for different modes: e.g. //,**, etc. in org-mode

> I think he is not asking about how to solve his particular problem, but
> suggesting a possible improvement to Emacs.

What I was trying to say is that `insert-pair-alist' doesn't need an
improvement in order to be buffer-local.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Proposal: make insert-pair-alist buffer local
  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 17:12 ` Juri Linkov
  2021-12-23 18:15   ` Eli Zaretskii
  2021-12-23 19:33 ` Stefan Monnier
  2 siblings, 1 reply; 7+ messages in thread
From: Juri Linkov @ 2021-12-23 17:12 UTC (permalink / raw)
  To: Pedro Andres Aranda Gutierrez; +Cc: emacs-devel

> 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



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Proposal: make insert-pair-alist buffer local
  2021-12-23 17:12 ` Juri Linkov
@ 2021-12-23 18:15   ` Eli Zaretskii
  0 siblings, 0 replies; 7+ messages in thread
From: Eli Zaretskii @ 2021-12-23 18:15 UTC (permalink / raw)
  To: Juri Linkov; +Cc: paaguti, emacs-devel

> From: Juri Linkov <juri@linkov.net>
> Date: Thu, 23 Dec 2021 19:12:54 +0200
> Cc: emacs-devel <emacs-devel@gnu.org>
> 
>   (and (memq buffer-file-coding-system '(utf-8 utf-8-unix utf-8-emacs-unix))

You want coding-system-base here instead of an (incomplete)
enumeration of possible variants.

(And requiring just UTF-8 is too restrictive: those characters can be
encoded by many more coding-systems.  It is better to use
unencodable-char-position instead.)



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Proposal: make insert-pair-alist buffer local
  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 17:12 ` Juri Linkov
@ 2021-12-23 19:33 ` Stefan Monnier
  2 siblings, 0 replies; 7+ messages in thread
From: Stefan Monnier @ 2021-12-23 19:33 UTC (permalink / raw)
  To: Pedro Andres Aranda Gutierrez; +Cc: emacs-devel

> 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?

FWIW, I consider `insert-pair` (and `insert-pair-alist`) obsoleted by
`electric-pair-mode`.


        Stefan




^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-12-23 19:33 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2021-12-23 18:15   ` Eli Zaretskii
2021-12-23 19:33 ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.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).