diff options
| author | Michal Nazarewicz | 2014-11-16 17:38:15 +0100 |
|---|---|---|
| committer | Michal Nazarewicz | 2014-11-18 00:46:50 +0100 |
| commit | b8104090075eb28dd6680cc9f8b0a49674ca369a (patch) | |
| tree | 6a4cb090a7ac881eb370edc8ac53938f3d291329 | |
| parent | 07556b0299b33b52cf352581bfdd6554819eea30 (diff) | |
| download | emacs-b8104090075eb28dd6680cc9f8b0a49674ca369a.tar.gz emacs-b8104090075eb28dd6680cc9f8b0a49674ca369a.zip | |
tildify.el: introduce a `tildify-space-string' variable
* textmodes/tildify.el (tildify-space-string): New variable for
specifying representation of a hard space -- a no-break space by
default. Being a buffer-local variable it is much easier to
handle than `tildify-string-alist' that has been used so far. It
also works better with derived modes.
(tildify-string-alist): Mark as obsolete.
* textmodes/tex-mode.el (tex-common-initialization): Set
`tildify-space-string' variable in all variants of TeX mode since
`tildify-string-alist' is now empty by default.
* nxml/nxml-mode.el (nxml-mode): Ditto in `nxml-mode'. If
encoding supports it use no-break space instead of character
entity; this changes previous default which used a numeric
reference.
* textmodes/sgml-mode.el (sgml-mode): ditto in `sgml-mode'. If
encoding does not support no-break space, use numeric reference;
this changes previous default which used named entity (“ ”)
in HTML mode.
| -rw-r--r-- | etc/NEWS | 3 | ||||
| -rw-r--r-- | lisp/ChangeLog | 23 | ||||
| -rw-r--r-- | lisp/nxml/nxml-mode.el | 10 | ||||
| -rw-r--r-- | lisp/textmodes/sgml-mode.el | 9 | ||||
| -rw-r--r-- | lisp/textmodes/tex-mode.el | 4 | ||||
| -rw-r--r-- | lisp/textmodes/tildify.el | 38 | ||||
| -rw-r--r-- | test/ChangeLog | 5 | ||||
| -rw-r--r-- | test/automated/tildify-tests.el | 4 |
8 files changed, 81 insertions, 15 deletions
| @@ -301,6 +301,9 @@ use PDF instead of DVI. | |||
| 301 | By default, 32 spaces and four TABs are considered to be too much but | 301 | By default, 32 spaces and four TABs are considered to be too much but |
| 302 | `whitespace-big-indent-regexp' can be configured to change that. | 302 | `whitespace-big-indent-regexp' can be configured to change that. |
| 303 | 303 | ||
| 304 | ** tildify: `tildify-space-string' variable has been added making | ||
| 305 | `tildify-string-alist' obsolete. | ||
| 306 | |||
| 304 | ** Obsolete packages | 307 | ** Obsolete packages |
| 305 | 308 | ||
| 306 | --- | 309 | --- |
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 696b384c3f9..33d341f8351 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,26 @@ | |||
| 1 | 2014-11-17 Michal Nazarewicz <mina86@mina86.com> | ||
| 2 | |||
| 3 | * textmodes/tildify.el (tildify-space-string): New variable for | ||
| 4 | specifying representation of a hard space -- a no-break space by | ||
| 5 | default. Being a buffer-local variable it is much easier to | ||
| 6 | handle than `tildify-string-alist' that has been used so far. It | ||
| 7 | also works better with derived modes. | ||
| 8 | (tildify-string-alist): Mark as obsolete. | ||
| 9 | |||
| 10 | * textmodes/tex-mode.el (tex-common-initialization): Set | ||
| 11 | `tildify-space-string' variable in all variants of TeX mode since | ||
| 12 | `tildify-string-alist' is now empty by default. | ||
| 13 | |||
| 14 | * nxml/nxml-mode.el (nxml-mode): Ditto in `nxml-mode'. If | ||
| 15 | encoding supports it use no-break space instead of character | ||
| 16 | entity; this changes previous default which used a numeric | ||
| 17 | reference. | ||
| 18 | |||
| 19 | * textmodes/sgml-mode.el (sgml-mode): ditto in `sgml-mode'. If | ||
| 20 | encoding does not support no-break space, use numeric reference; | ||
| 21 | this changes previous default which used named entity (? ?) | ||
| 22 | in HTML mode. | ||
| 23 | |||
| 1 | 2014-11-17 Ulf Jasper <ulf.jasper@web.de> | 24 | 2014-11-17 Ulf Jasper <ulf.jasper@web.de> |
| 2 | 25 | ||
| 3 | Fix bug#5433. | 26 | Fix bug#5433. |
diff --git a/lisp/nxml/nxml-mode.el b/lisp/nxml/nxml-mode.el index 4859bbc7a77..47f806693df 100644 --- a/lisp/nxml/nxml-mode.el +++ b/lisp/nxml/nxml-mode.el | |||
| @@ -449,6 +449,8 @@ reference.") | |||
| 449 | (when rng-validate-mode | 449 | (when rng-validate-mode |
| 450 | (rng-validate-while-idle (current-buffer))))) | 450 | (rng-validate-while-idle (current-buffer))))) |
| 451 | 451 | ||
| 452 | (defvar tildify-space-string) | ||
| 453 | |||
| 452 | ;;;###autoload | 454 | ;;;###autoload |
| 453 | (define-derived-mode nxml-mode text-mode "nXML" | 455 | (define-derived-mode nxml-mode text-mode "nXML" |
| 454 | ;; We use C-c C-i instead of \\[nxml-balanced-close-start-tag-inline] | 456 | ;; We use C-c C-i instead of \\[nxml-balanced-close-start-tag-inline] |
| @@ -505,6 +507,14 @@ be treated as a single markup item, set the variable | |||
| 505 | Many aspects this mode can be customized using | 507 | Many aspects this mode can be customized using |
| 506 | \\[customize-group] nxml RET." | 508 | \\[customize-group] nxml RET." |
| 507 | ;; (kill-all-local-variables) | 509 | ;; (kill-all-local-variables) |
| 510 | ;; If encoding does not allow non-break space character, use reference. | ||
| 511 | ;; FIXME: This duplicates code from sgml-mode, perhaps derive from it? | ||
| 512 | ;; FIXME: Perhaps use if possible (e.g. XHTML)? | ||
| 513 | (setq-local tildify-space-string | ||
| 514 | (if (equal (decode-coding-string | ||
| 515 | (encode-coding-string " " buffer-file-coding-system) | ||
| 516 | buffer-file-coding-system) " ") | ||
| 517 | " " " ")) | ||
| 508 | (set (make-local-variable 'mode-line-process) '((nxml-degraded "/degraded"))) | 518 | (set (make-local-variable 'mode-line-process) '((nxml-degraded "/degraded"))) |
| 509 | ;; We'll determine the fill prefix ourselves | 519 | ;; We'll determine the fill prefix ourselves |
| 510 | (make-local-variable 'adaptive-fill-mode) | 520 | (make-local-variable 'adaptive-fill-mode) |
diff --git a/lisp/textmodes/sgml-mode.el b/lisp/textmodes/sgml-mode.el index 39ac0621733..9d1cb0373fa 100644 --- a/lisp/textmodes/sgml-mode.el +++ b/lisp/textmodes/sgml-mode.el | |||
| @@ -456,6 +456,8 @@ This function is designed for use in `fill-nobreak-predicate'. | |||
| 456 | (skip-chars-backward "/?!") | 456 | (skip-chars-backward "/?!") |
| 457 | (eq (char-before) ?<)))) | 457 | (eq (char-before) ?<)))) |
| 458 | 458 | ||
| 459 | (defvar tildify-space-string) | ||
| 460 | |||
| 459 | ;;;###autoload | 461 | ;;;###autoload |
| 460 | (define-derived-mode sgml-mode text-mode '(sgml-xml-mode "XML" "SGML") | 462 | (define-derived-mode sgml-mode text-mode '(sgml-xml-mode "XML" "SGML") |
| 461 | "Major mode for editing SGML documents. | 463 | "Major mode for editing SGML documents. |
| @@ -477,6 +479,13 @@ Do \\[describe-key] on the following bindings to discover what they do. | |||
| 477 | \\{sgml-mode-map}" | 479 | \\{sgml-mode-map}" |
| 478 | (make-local-variable 'sgml-saved-validate-command) | 480 | (make-local-variable 'sgml-saved-validate-command) |
| 479 | (make-local-variable 'facemenu-end-add-face) | 481 | (make-local-variable 'facemenu-end-add-face) |
| 482 | ;; If encoding does not allow non-break space character, use reference. | ||
| 483 | ;; FIXME: Perhaps use if possible (e.g. when we know its HTML)? | ||
| 484 | (setq-local tildify-space-string | ||
| 485 | (if (equal (decode-coding-string | ||
| 486 | (encode-coding-string " " buffer-file-coding-system) | ||
| 487 | buffer-file-coding-system) " ") | ||
| 488 | " " " ")) | ||
| 480 | ;;(make-local-variable 'facemenu-remove-face-function) | 489 | ;;(make-local-variable 'facemenu-remove-face-function) |
| 481 | ;; A start or end tag by itself on a line separates a paragraph. | 490 | ;; A start or end tag by itself on a line separates a paragraph. |
| 482 | ;; This is desirable because SGML discards a newline that appears | 491 | ;; This is desirable because SGML discards a newline that appears |
diff --git a/lisp/textmodes/tex-mode.el b/lisp/textmodes/tex-mode.el index bc10eab0498..0cfc0cfe3dc 100644 --- a/lisp/textmodes/tex-mode.el +++ b/lisp/textmodes/tex-mode.el | |||
| @@ -1203,9 +1203,13 @@ Entering SliTeX mode runs the hook `text-mode-hook', then the hook | |||
| 1203 | (setq tex-command slitex-run-command) | 1203 | (setq tex-command slitex-run-command) |
| 1204 | (setq tex-start-of-header "\\\\documentstyle{slides}\\|\\\\documentclass{slides}")) | 1204 | (setq tex-start-of-header "\\\\documentstyle{slides}\\|\\\\documentclass{slides}")) |
| 1205 | 1205 | ||
| 1206 | (defvar tildify-space-string) | ||
| 1207 | |||
| 1206 | (defun tex-common-initialization () | 1208 | (defun tex-common-initialization () |
| 1207 | ;; Regexp isearch should accept newline and formfeed as whitespace. | 1209 | ;; Regexp isearch should accept newline and formfeed as whitespace. |
| 1208 | (setq-local search-whitespace-regexp "[ \t\r\n\f]+") | 1210 | (setq-local search-whitespace-regexp "[ \t\r\n\f]+") |
| 1211 | ;; Use tilde as hard-space character in tildify package. | ||
| 1212 | (setq-local tildify-space-string "~") | ||
| 1209 | ;; A line containing just $$ is treated as a paragraph separator. | 1213 | ;; A line containing just $$ is treated as a paragraph separator. |
| 1210 | (setq-local paragraph-start "[ \t]*$\\|[\f\\\\%]\\|[ \t]*\\$\\$") | 1214 | (setq-local paragraph-start "[ \t]*$\\|[\f\\\\%]\\|[ \t]*\\$\\$") |
| 1211 | ;; A line starting with $$ starts a paragraph, | 1215 | ;; A line starting with $$ starts a paragraph, |
diff --git a/lisp/textmodes/tildify.el b/lisp/textmodes/tildify.el index 91f5a38ce0b..865dcecbecc 100644 --- a/lisp/textmodes/tildify.el +++ b/lisp/textmodes/tildify.el | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | ;; Author: Milan Zamazal <pdm@zamazal.org> | 5 | ;; Author: Milan Zamazal <pdm@zamazal.org> |
| 6 | ;; Michal Nazarewicz <mina86@mina86.com> | 6 | ;; Michal Nazarewicz <mina86@mina86.com> |
| 7 | ;; Version: 4.5.4 | 7 | ;; Version: 4.5.5 |
| 8 | ;; Keywords: text, TeX, SGML, wp | 8 | ;; Keywords: text, TeX, SGML, wp |
| 9 | 9 | ||
| 10 | ;; This file is part of GNU Emacs. | 10 | ;; This file is part of GNU Emacs. |
| @@ -86,15 +86,24 @@ mode, the item for the mode SYMBOL is looked up in the alist instead." | |||
| 86 | (integer :tag "Group ")) | 86 | (integer :tag "Group ")) |
| 87 | (symbol :tag "Like other"))))) | 87 | (symbol :tag "Like other"))))) |
| 88 | 88 | ||
| 89 | (defcustom tildify-string-alist | 89 | (defcustom tildify-space-string "\u00A0" |
| 90 | '((latex-mode . "~") | 90 | "Representation of a hard (a.k.a. no-break) space in current major mode. |
| 91 | (tex-mode . latex-mode) | 91 | |
| 92 | (plain-tex-mode . latex-mode) | 92 | Used by `tildify-buffer' in places where space is required but line |
| 93 | (sgml-mode . " ") | 93 | cannot be broken. For example \"~\" for TeX or \" \" for SGML, |
| 94 | (html-mode . sgml-mode) | 94 | HTML and XML modes. A no-break space Unicode character (\"\\u00A0\") |
| 95 | (xml-mode . " ") ; XML does not define use numeric reference | 95 | might be used for other modes if compatible encoding is used. |
| 96 | (nxml-mode . xml-mode) | 96 | |
| 97 | (t . " ")) | 97 | If nil, current major mode has no way to represent a hard space." |
| 98 | :version "25.1" | ||
| 99 | :group 'tildify | ||
| 100 | :type '(choice (const :tag "Space character (no hard-space representation)" | ||
| 101 | " ") | ||
| 102 | (const :tag "No-break space (U+00A0)" "\u00A0") | ||
| 103 | (string :tag "Custom string")) | ||
| 104 | :safe t) | ||
| 105 | |||
| 106 | (defcustom tildify-string-alist () | ||
| 98 | "Alist specifying what is a hard space in the current major mode. | 107 | "Alist specifying what is a hard space in the current major mode. |
| 99 | 108 | ||
| 100 | Each alist item is of the form (MAJOR-MODE . STRING) or | 109 | Each alist item is of the form (MAJOR-MODE . STRING) or |
| @@ -118,6 +127,8 @@ mode, the item for the mode SYMBOL is looked up in the alist instead." | |||
| 118 | (choice (const :tag "No-break space (U+00A0)" "\u00A0") | 127 | (choice (const :tag "No-break space (U+00A0)" "\u00A0") |
| 119 | (string :tag "String ") | 128 | (string :tag "String ") |
| 120 | (symbol :tag "Like other"))))) | 129 | (symbol :tag "Like other"))))) |
| 130 | (make-obsolete-variable 'tildify-string-alist | ||
| 131 | 'tildify-space-string "25.1") | ||
| 121 | 132 | ||
| 122 | (defcustom tildify-ignored-environments-alist | 133 | (defcustom tildify-ignored-environments-alist |
| 123 | `((latex-mode | 134 | `((latex-mode |
| @@ -193,7 +204,7 @@ END-REGEX defines end of the corresponding text part and can be either: | |||
| 193 | ;;;###autoload | 204 | ;;;###autoload |
| 194 | (defun tildify-region (beg end &optional dont-ask) | 205 | (defun tildify-region (beg end &optional dont-ask) |
| 195 | "Add hard spaces in the region between BEG and END. | 206 | "Add hard spaces in the region between BEG and END. |
| 196 | See variables `tildify-pattern-alist', `tildify-string-alist', and | 207 | See variables `tildify-pattern-alist', `tildify-space-string', and |
| 197 | `tildify-ignored-environments-alist' for information about configuration | 208 | `tildify-ignored-environments-alist' for information about configuration |
| 198 | parameters. | 209 | parameters. |
| 199 | This function performs no refilling of the changed text. | 210 | This function performs no refilling of the changed text. |
| @@ -214,7 +225,7 @@ won't be prompted for confirmation of each substitution." | |||
| 214 | ;;;###autoload | 225 | ;;;###autoload |
| 215 | (defun tildify-buffer (&optional dont-ask) | 226 | (defun tildify-buffer (&optional dont-ask) |
| 216 | "Add hard spaces in the current buffer. | 227 | "Add hard spaces in the current buffer. |
| 217 | See variables `tildify-pattern-alist', `tildify-string-alist', and | 228 | See variables `tildify-pattern-alist', `tildify-space-string', and |
| 218 | `tildify-ignored-environments-alist' for information about configuration | 229 | `tildify-ignored-environments-alist' for information about configuration |
| 219 | parameters. | 230 | parameters. |
| 220 | This function performs no refilling of the changed text. | 231 | This function performs no refilling of the changed text. |
| @@ -303,7 +314,8 @@ replacements done and response is one of symbols: t (all right), nil | |||
| 303 | (let* ((alist (tildify--pick-alist-entry tildify-pattern-alist)) | 314 | (let* ((alist (tildify--pick-alist-entry tildify-pattern-alist)) |
| 304 | (regexp (car alist)) | 315 | (regexp (car alist)) |
| 305 | (match-number (cadr alist)) | 316 | (match-number (cadr alist)) |
| 306 | (tilde (tildify--pick-alist-entry tildify-string-alist)) | 317 | (tilde (or (tildify--pick-alist-entry tildify-string-alist) |
| 318 | tildify-space-string)) | ||
| 307 | (end-marker (copy-marker end)) | 319 | (end-marker (copy-marker end)) |
| 308 | answer | 320 | answer |
| 309 | bad-answer | 321 | bad-answer |
diff --git a/test/ChangeLog b/test/ChangeLog index 2dfd5151f09..1c739d456ac 100644 --- a/test/ChangeLog +++ b/test/ChangeLog | |||
| @@ -1,3 +1,8 @@ | |||
| 1 | 2014-11-17 Michal Nazarewicz <mina86@mina86.com> | ||
| 2 | |||
| 3 | * automated/tildify-tests.el (tildify-test-html, tildify-test-xml): | ||
| 4 | HTML and XML now use no-break space as hard space. Update tests. | ||
| 5 | |||
| 1 | 2014-11-17 Glenn Morris <rgm@gnu.org> | 6 | 2014-11-17 Glenn Morris <rgm@gnu.org> |
| 2 | 7 | ||
| 3 | * automated/occur-tests.el (occur-test-case, occur-test-create): | 8 | * automated/occur-tests.el (occur-test-case, occur-test-create): |
diff --git a/test/automated/tildify-tests.el b/test/automated/tildify-tests.el index 53c2e620195..e532cf00686 100644 --- a/test/automated/tildify-tests.el +++ b/test/automated/tildify-tests.el | |||
| @@ -73,7 +73,7 @@ after `tildify-buffer' is run." | |||
| 73 | (ert-deftest tildify-test-html () | 73 | (ert-deftest tildify-test-html () |
| 74 | "Tests tildification in an HTML document" | 74 | "Tests tildification in an HTML document" |
| 75 | (let* ((sentence (tildify-test--example-sentence " ")) | 75 | (let* ((sentence (tildify-test--example-sentence " ")) |
| 76 | (with-nbsp (tildify-test--example-sentence " "))) | 76 | (with-nbsp (tildify-test--example-sentence " "))) |
| 77 | (tildify-test--test '(html-mode sgml-mode) | 77 | (tildify-test--test '(html-mode sgml-mode) |
| 78 | (tildify-test--example-html sentence sentence) | 78 | (tildify-test--example-html sentence sentence) |
| 79 | (tildify-test--example-html sentence with-nbsp)))) | 79 | (tildify-test--example-html sentence with-nbsp)))) |
| @@ -81,7 +81,7 @@ after `tildify-buffer' is run." | |||
| 81 | (ert-deftest tildify-test-xml () | 81 | (ert-deftest tildify-test-xml () |
| 82 | "Tests tildification in an XML document" | 82 | "Tests tildification in an XML document" |
| 83 | (let* ((sentence (tildify-test--example-sentence " ")) | 83 | (let* ((sentence (tildify-test--example-sentence " ")) |
| 84 | (with-nbsp (tildify-test--example-sentence " "))) | 84 | (with-nbsp (tildify-test--example-sentence " "))) |
| 85 | (tildify-test--test '(nxml-mode) | 85 | (tildify-test--test '(nxml-mode) |
| 86 | (tildify-test--example-html sentence sentence t) | 86 | (tildify-test--example-html sentence sentence t) |
| 87 | (tildify-test--example-html sentence with-nbsp t)))) | 87 | (tildify-test--example-html sentence with-nbsp t)))) |