diff options
| author | Göktuğ Kayaalp | 2016-10-27 08:05:24 -0700 |
|---|---|---|
| committer | Paul Eggert | 2016-10-27 08:11:25 -0700 |
| commit | 11d380a029640eeb99badfa31976e9c47f53b002 (patch) | |
| tree | 42f42457eece58a84b1084a5ba218b3a090bc05b | |
| parent | 53a0562b2c69d7598c51c03417d8daab46f375c9 (diff) | |
| download | emacs-11d380a029640eeb99badfa31976e9c47f53b002.tar.gz emacs-11d380a029640eeb99badfa31976e9c47f53b002.zip | |
New user variable 'electric-quote-chars'
* doc/emacs/text.texi (Quotation Marks), etc/NEWS: Document this.
* lisp/electric.el (electric-quote-chars): New defcustom.
(electric-quote-post-self-insert-function): Use it.
| -rw-r--r-- | doc/emacs/text.texi | 14 | ||||
| -rw-r--r-- | etc/NEWS | 5 | ||||
| -rw-r--r-- | lisp/electric.el | 53 |
3 files changed, 50 insertions, 22 deletions
diff --git a/doc/emacs/text.texi b/doc/emacs/text.texi index 7fa0804d270..4c6a1ffbdd2 100644 --- a/doc/emacs/text.texi +++ b/doc/emacs/text.texi | |||
| @@ -412,6 +412,7 @@ beginning of a line. | |||
| 412 | @cindex mode, Electric Quote | 412 | @cindex mode, Electric Quote |
| 413 | @cindex curly quotes | 413 | @cindex curly quotes |
| 414 | @cindex curved quotes | 414 | @cindex curved quotes |
| 415 | @cindex guillemets | ||
| 415 | @findex electric-quote-mode | 416 | @findex electric-quote-mode |
| 416 | One common way to quote is the typewriter convention, which quotes | 417 | One common way to quote is the typewriter convention, which quotes |
| 417 | using straight apostrophes @t{'like this'} or double-quotes @t{"like | 418 | using straight apostrophes @t{'like this'} or double-quotes @t{"like |
| @@ -420,9 +421,15 @@ left and right single or double quotation marks @t{‘like this’} or | |||
| 420 | @t{“like this”}. In text files, typewriter quotes are simple and | 421 | @t{“like this”}. In text files, typewriter quotes are simple and |
| 421 | portable; curved quotes are less ambiguous and typically look nicer. | 422 | portable; curved quotes are less ambiguous and typically look nicer. |
| 422 | 423 | ||
| 424 | @vindex electric-quote-chars | ||
| 423 | Electric Quote mode makes it easier to type curved quotes. As you | 425 | Electric Quote mode makes it easier to type curved quotes. As you |
| 424 | type characters it optionally converts @t{`} to @t{‘}, @t{'} to @t{’}, | 426 | type characters it optionally converts @t{`} to @t{‘}, @t{'} to @t{’}, |
| 425 | @t{``} to @t{“}, and @t{''} to @t{”}. | 427 | @t{``} to @t{“}, and @t{''} to @t{”}. It's possible to change the |
| 428 | default quotes listed above, by customizing the variable | ||
| 429 | @code{electric-quote-chars}, a list of four characters, where the | ||
| 430 | items correspond to the left single quote, the right single quote, the | ||
| 431 | left double quote and the right double quote, respectively, whose | ||
| 432 | default value is @code{'(?‘ ?’ ?“ ?”)}. | ||
| 426 | 433 | ||
| 427 | @vindex electric-quote-paragraph | 434 | @vindex electric-quote-paragraph |
| 428 | @vindex electric-quote-comment | 435 | @vindex electric-quote-comment |
| @@ -443,7 +450,10 @@ type @kbd{C-q `} or @kbd{C-q '} instead of @kbd{`} or @kbd{'}. To | |||
| 443 | insert a curved quote even when Electric Quote is disabled or | 450 | insert a curved quote even when Electric Quote is disabled or |
| 444 | inactive, you can type @kbd{C-x 8 [} for @t{‘}, @kbd{C-x 8 ]} for | 451 | inactive, you can type @kbd{C-x 8 [} for @t{‘}, @kbd{C-x 8 ]} for |
| 445 | @t{’}, @kbd{C-x 8 @{} for @t{“}, and @kbd{C-x 8 @}} for @t{”}. | 452 | @t{’}, @kbd{C-x 8 @{} for @t{“}, and @kbd{C-x 8 @}} for @t{”}. |
| 446 | @xref{Inserting Text}. | 453 | @xref{Inserting Text}. Note that the value of |
| 454 | @code{electric-quote-chars} does not affect these keybindings, they | ||
| 455 | are not keybindings of @code{electric-quote-mode} but bound in | ||
| 456 | @code{global-map}. | ||
| 447 | 457 | ||
| 448 | @node Filling | 458 | @node Filling |
| 449 | @section Filling Text | 459 | @section Filling Text |
| @@ -61,6 +61,11 @@ affected by this, as SGI stopped supporting IRIX in December 2013. | |||
| 61 | 61 | ||
| 62 | * Changes in Emacs 26.1 | 62 | * Changes in Emacs 26.1 |
| 63 | 63 | ||
| 64 | +++ | ||
| 65 | ** The new user variable 'electric-quote-chars' provides a list | ||
| 66 | of curved quotes for 'electric-quote-mode', allowing user to choose | ||
| 67 | the types of quotes to be used. | ||
| 68 | |||
| 64 | --- | 69 | --- |
| 65 | The group 'wp', whose label was "text", is now deprecated. | 70 | The group 'wp', whose label was "text", is now deprecated. |
| 66 | Use the new group 'text', which inherits from 'wp', instead. | 71 | Use the new group 'text', which inherits from 'wp', instead. |
diff --git a/lisp/electric.el b/lisp/electric.el index f35f8b99db3..19cded25dfb 100644 --- a/lisp/electric.el +++ b/lisp/electric.el | |||
| @@ -425,6 +425,13 @@ The variable `electric-layout-rules' says when and how to insert newlines." | |||
| 425 | :version "25.1" | 425 | :version "25.1" |
| 426 | :type 'boolean :safe 'booleanp :group 'electricity) | 426 | :type 'boolean :safe 'booleanp :group 'electricity) |
| 427 | 427 | ||
| 428 | (defcustom electric-quote-chars '(?‘ ?’ ?“ ?”) | ||
| 429 | "Curved quote characters for `electric-quote-mode'. | ||
| 430 | The items correspond to the left single quote, the right single | ||
| 431 | quote, the left double quote, and the right double quote, respectively." | ||
| 432 | :version "25.1" | ||
| 433 | :type 'list :safe 'listp :group 'electricity) | ||
| 434 | |||
| 428 | (defcustom electric-quote-paragraph t | 435 | (defcustom electric-quote-paragraph t |
| 429 | "Non-nil means to use electric quoting in text paragraphs." | 436 | "Non-nil means to use electric quoting in text paragraphs." |
| 430 | :version "25.1" | 437 | :version "25.1" |
| @@ -451,26 +458,29 @@ This requotes when a quoting key is typed." | |||
| 451 | (derived-mode-p 'text-mode) | 458 | (derived-mode-p 'text-mode) |
| 452 | (or (eq last-command-event ?\`) | 459 | (or (eq last-command-event ?\`) |
| 453 | (save-excursion (backward-paragraph) (point))))))) | 460 | (save-excursion (backward-paragraph) (point))))))) |
| 454 | (when start | 461 | (pcase electric-quote-chars |
| 455 | (save-excursion | 462 | (`(,q1 ,q2 ,q3 ,q4) |
| 456 | (if (eq last-command-event ?\`) | 463 | (when start |
| 457 | (cond ((search-backward "‘`" (- (point) 2) t) | 464 | (save-excursion |
| 458 | (replace-match "“") | 465 | (if (eq last-command-event ?\`) |
| 459 | (when (and electric-pair-mode | 466 | (cond ((search-backward (string q1 ?`) (- (point) 2) t) |
| 460 | (eq (cdr-safe | 467 | (replace-match (string q3)) |
| 461 | (assq ?‘ electric-pair-text-pairs)) | 468 | (when (and electric-pair-mode |
| 462 | (char-after))) | 469 | (eq (cdr-safe |
| 463 | (delete-char 1)) | 470 | (assq q1 electric-pair-text-pairs)) |
| 464 | (setq last-command-event ?“)) | 471 | (char-after))) |
| 465 | ((search-backward "`" (1- (point)) t) | 472 | (delete-char 1)) |
| 466 | (replace-match "‘") | 473 | (setq last-command-event q3)) |
| 467 | (setq last-command-event ?‘))) | 474 | ((search-backward "`" (1- (point)) t) |
| 468 | (cond ((search-backward "’'" (- (point) 2) t) | 475 | (replace-match (string q1)) |
| 469 | (replace-match "”") | 476 | (setq last-command-event q1))) |
| 470 | (setq last-command-event ?”)) | 477 | (cond ((search-backward (string q2 ?') (- (point) 2) t) |
| 471 | ((search-backward "'" (1- (point)) t) | 478 | (replace-match (string q4)) |
| 472 | (replace-match "’") | 479 | (setq last-command-event q4)) |
| 473 | (setq last-command-event ?’))))))))) | 480 | ((search-backward "'" (1- (point)) t) |
| 481 | (replace-match (string q2)) | ||
| 482 | (setq last-command-event q2))))))) | ||
| 483 | (_ (error "‘electric-quote-chars’ must contain exactly 4 characters.")))))) | ||
| 474 | 484 | ||
| 475 | (put 'electric-quote-post-self-insert-function 'priority 10) | 485 | (put 'electric-quote-post-self-insert-function 'priority 10) |
| 476 | 486 | ||
| @@ -487,6 +497,9 @@ and text paragraphs, and these are selectively controlled with | |||
| 487 | `electric-quote-comment', `electric-quote-string', and | 497 | `electric-quote-comment', `electric-quote-string', and |
| 488 | `electric-quote-paragraph'. | 498 | `electric-quote-paragraph'. |
| 489 | 499 | ||
| 500 | Customize `electric-quote-chars' in order to use quote chars | ||
| 501 | other than the ones listed here. | ||
| 502 | |||
| 490 | This is a global minor mode. To toggle the mode in a single buffer, | 503 | This is a global minor mode. To toggle the mode in a single buffer, |
| 491 | use `electric-quote-local-mode'." | 504 | use `electric-quote-local-mode'." |
| 492 | :global t :group 'electricity | 505 | :global t :group 'electricity |