aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorMichal Nazarewicz2014-11-16 17:38:15 +0100
committerMichal Nazarewicz2014-11-18 00:46:50 +0100
commitb8104090075eb28dd6680cc9f8b0a49674ca369a (patch)
tree6a4cb090a7ac881eb370edc8ac53938f3d291329 /lisp
parent07556b0299b33b52cf352581bfdd6554819eea30 (diff)
downloademacs-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.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/ChangeLog23
-rw-r--r--lisp/nxml/nxml-mode.el10
-rw-r--r--lisp/textmodes/sgml-mode.el9
-rw-r--r--lisp/textmodes/tex-mode.el4
-rw-r--r--lisp/textmodes/tildify.el38
5 files changed, 71 insertions, 13 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 696b384c3f9..33d341f8351 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,26 @@
12014-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 (?&nbsp;?)
22 in HTML mode.
23
12014-11-17 Ulf Jasper <ulf.jasper@web.de> 242014-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
505Many aspects this mode can be customized using 507Many 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 &nbsp; 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 " " "&#160;"))
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 &nbsp; 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 " " "&#160;"))
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) 92Used by `tildify-buffer' in places where space is required but line
93 (sgml-mode . "&nbsp;") 93cannot be broken. For example \"~\" for TeX or \"&#160;\" for SGML,
94 (html-mode . sgml-mode) 94HTML and XML modes. A no-break space Unicode character (\"\\u00A0\")
95 (xml-mode . "&#160;") ; XML does not define &nbsp; use numeric reference 95might be used for other modes if compatible encoding is used.
96 (nxml-mode . xml-mode) 96
97 (t . " ")) 97If 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
100Each alist item is of the form (MAJOR-MODE . STRING) or 109Each 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.
196See variables `tildify-pattern-alist', `tildify-string-alist', and 207See 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
198parameters. 209parameters.
199This function performs no refilling of the changed text. 210This 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.
217See variables `tildify-pattern-alist', `tildify-string-alist', and 228See 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
219parameters. 230parameters.
220This function performs no refilling of the changed text. 231This 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