]> git.eshelyaron.com Git - emacs.git/commitdiff
tildify.el: introduce a `tildify-space-string' variable
authorMichal Nazarewicz <mina86@mina86.com>
Sun, 16 Nov 2014 16:38:15 +0000 (17:38 +0100)
committerMichal Nazarewicz <mina86@mina86.com>
Mon, 17 Nov 2014 23:46:50 +0000 (00:46 +0100)
* 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 (“&nbsp;”)
in HTML mode.

etc/NEWS
lisp/ChangeLog
lisp/nxml/nxml-mode.el
lisp/textmodes/sgml-mode.el
lisp/textmodes/tex-mode.el
lisp/textmodes/tildify.el
test/ChangeLog
test/automated/tildify-tests.el

index ecbbf74771346fb41ba10fd7fc36cd3eb8bf898c..d03ce7cc873847c0c7db5be2ad103c78d2afa667 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -301,6 +301,9 @@ use PDF instead of DVI.
 By default, 32 spaces and four TABs are considered to be too much but
 `whitespace-big-indent-regexp' can be configured to change that.
 
+** tildify: `tildify-space-string' variable has been added making
+`tildify-string-alist' obsolete.
+
 ** Obsolete packages
 
 ---
index 696b384c3f94838be894ae27520f803de783114b..33d341f8351bdc0477bfeb0719be13ed57c091a6 100644 (file)
@@ -1,3 +1,26 @@
+2014-11-17  Michal Nazarewicz  <mina86@mina86.com>
+
+       * 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 (?&nbsp;?)
+       in HTML mode.
+
 2014-11-17  Ulf Jasper  <ulf.jasper@web.de>
 
        Fix bug#5433.
index 4859bbc7a77b2f41fe3e0a641c1d46ca7e1de076..47f806693df80b1e7ec2214405a1468dc4ad8082 100644 (file)
@@ -449,6 +449,8 @@ reference.")
     (when rng-validate-mode
       (rng-validate-while-idle (current-buffer)))))
 
+(defvar tildify-space-string)
+
 ;;;###autoload
 (define-derived-mode nxml-mode text-mode "nXML"
   ;; 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
 Many aspects this mode can be customized using
 \\[customize-group] nxml RET."
   ;; (kill-all-local-variables)
+  ;; If encoding does not allow non-break space character, use reference.
+  ;; FIXME: This duplicates code from sgml-mode, perhaps derive from it?
+  ;; FIXME: Perhaps use &nbsp; if possible (e.g. XHTML)?
+  (setq-local tildify-space-string
+              (if (equal (decode-coding-string
+                          (encode-coding-string " " buffer-file-coding-system)
+                          buffer-file-coding-system) " ")
+                  " " "&#160;"))
   (set (make-local-variable 'mode-line-process) '((nxml-degraded "/degraded")))
   ;; We'll determine the fill prefix ourselves
   (make-local-variable 'adaptive-fill-mode)
index 39ac0621733afecebcd06882bd610857163d3095..9d1cb0373fa1e0838bc76c601e2156d647da2620 100644 (file)
@@ -456,6 +456,8 @@ This function is designed for use in `fill-nobreak-predicate'.
         (skip-chars-backward "/?!")
         (eq (char-before) ?<))))
 
+(defvar tildify-space-string)
+
 ;;;###autoload
 (define-derived-mode sgml-mode text-mode '(sgml-xml-mode "XML" "SGML")
   "Major mode for editing SGML documents.
@@ -477,6 +479,13 @@ Do \\[describe-key] on the following bindings to discover what they do.
 \\{sgml-mode-map}"
   (make-local-variable 'sgml-saved-validate-command)
   (make-local-variable 'facemenu-end-add-face)
+  ;; If encoding does not allow non-break space character, use reference.
+  ;; FIXME: Perhaps use &nbsp; if possible (e.g. when we know its HTML)?
+  (setq-local tildify-space-string
+              (if (equal (decode-coding-string
+                          (encode-coding-string " " buffer-file-coding-system)
+                          buffer-file-coding-system) " ")
+                  " " "&#160;"))
   ;;(make-local-variable 'facemenu-remove-face-function)
   ;; A start or end tag by itself on a line separates a paragraph.
   ;; This is desirable because SGML discards a newline that appears
index bc10eab0498102c1b31c96f672112d56cf09410c..0cfc0cfe3dc1831cb9cb375d7500b81da885ed54 100644 (file)
@@ -1203,9 +1203,13 @@ Entering SliTeX mode runs the hook `text-mode-hook', then the hook
   (setq tex-command slitex-run-command)
   (setq tex-start-of-header "\\\\documentstyle{slides}\\|\\\\documentclass{slides}"))
 
+(defvar tildify-space-string)
+
 (defun tex-common-initialization ()
   ;; Regexp isearch should accept newline and formfeed as whitespace.
   (setq-local search-whitespace-regexp "[ \t\r\n\f]+")
+  ;; Use tilde as hard-space character in tildify package.
+  (setq-local tildify-space-string "~")
   ;; A line containing just $$ is treated as a paragraph separator.
   (setq-local paragraph-start "[ \t]*$\\|[\f\\\\%]\\|[ \t]*\\$\\$")
   ;; A line starting with $$ starts a paragraph,
index 91f5a38ce0bb1054ef4c8bd799c15a79e6baa7df..865dcecbecc966287f8fa3703af64f33611c0173 100644 (file)
@@ -4,7 +4,7 @@
 
 ;; Author:     Milan Zamazal <pdm@zamazal.org>
 ;;             Michal Nazarewicz <mina86@mina86.com>
-;; Version:    4.5.4
+;; Version:    4.5.5
 ;; Keywords:   text, TeX, SGML, wp
 
 ;; 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."
                                        (integer :tag "Group "))
                                (symbol :tag "Like other")))))
 
-(defcustom tildify-string-alist
-  '((latex-mode . "~")
-    (tex-mode . latex-mode)
-    (plain-tex-mode . latex-mode)
-    (sgml-mode . "&nbsp;")
-    (html-mode . sgml-mode)
-    (xml-mode . "&#160;") ; XML does not define &nbsp; use numeric reference
-    (nxml-mode . xml-mode)
-    (t . " "))
+(defcustom tildify-space-string "\u00A0"
+  "Representation of a hard (a.k.a. no-break) space in current major mode.
+
+Used by `tildify-buffer' in places where space is required but line
+cannot be broken.  For example \"~\" for TeX or \"&#160;\" for SGML,
+HTML and XML modes.  A no-break space Unicode character (\"\\u00A0\")
+might be used for other modes if compatible encoding is used.
+
+If nil, current major mode has no way to represent a hard space."
+  :version "25.1"
+  :group 'tildify
+  :type '(choice (const :tag "Space character (no hard-space representation)"
+                        " ")
+                 (const :tag "No-break space (U+00A0)" "\u00A0")
+                 (string :tag "Custom string"))
+  :safe t)
+
+(defcustom tildify-string-alist ()
   "Alist specifying what is a hard space in the current major mode.
 
 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."
                        (choice (const  :tag "No-break space (U+00A0)" "\u00A0")
                                (string :tag "String    ")
                                (symbol :tag "Like other")))))
+(make-obsolete-variable 'tildify-string-alist
+                        'tildify-space-string "25.1")
 
 (defcustom tildify-ignored-environments-alist
   `((latex-mode
@@ -193,7 +204,7 @@ END-REGEX defines end of the corresponding text part and can be either:
 ;;;###autoload
 (defun tildify-region (beg end &optional dont-ask)
   "Add hard spaces in the region between BEG and END.
-See variables `tildify-pattern-alist', `tildify-string-alist', and
+See variables `tildify-pattern-alist', `tildify-space-string', and
 `tildify-ignored-environments-alist' for information about configuration
 parameters.
 This function performs no refilling of the changed text.
@@ -214,7 +225,7 @@ won't be prompted for confirmation of each substitution."
 ;;;###autoload
 (defun tildify-buffer (&optional dont-ask)
   "Add hard spaces in the current buffer.
-See variables `tildify-pattern-alist', `tildify-string-alist', and
+See variables `tildify-pattern-alist', `tildify-space-string', and
 `tildify-ignored-environments-alist' for information about configuration
 parameters.
 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
     (let* ((alist (tildify--pick-alist-entry tildify-pattern-alist))
           (regexp (car alist))
           (match-number (cadr alist))
-          (tilde (tildify--pick-alist-entry tildify-string-alist))
+          (tilde (or (tildify--pick-alist-entry tildify-string-alist)
+                     tildify-space-string))
           (end-marker (copy-marker end))
           answer
           bad-answer
index 2dfd5151f0950d84a93660af92b7738b995c72fd..1c739d456acf0d00a5fc3d695174b97a6c980119 100644 (file)
@@ -1,3 +1,8 @@
+2014-11-17  Michal Nazarewicz  <mina86@mina86.com>
+
+       * automated/tildify-tests.el (tildify-test-html, tildify-test-xml):
+       HTML and XML now use no-break space as hard space.  Update tests.
+
 2014-11-17  Glenn Morris  <rgm@gnu.org>
 
        * automated/occur-tests.el (occur-test-case, occur-test-create):
index 53c2e620195bcbe3895054e2cafaf8a6c7df9f4d..e532cf00686c4a05384e698050492ebe22ebdbac 100644 (file)
@@ -73,7 +73,7 @@ after `tildify-buffer' is run."
 (ert-deftest tildify-test-html ()
   "Tests tildification in an HTML document"
   (let* ((sentence (tildify-test--example-sentence " "))
-         (with-nbsp (tildify-test--example-sentence "&nbsp;")))
+         (with-nbsp (tildify-test--example-sentence " ")))
     (tildify-test--test '(html-mode sgml-mode)
                         (tildify-test--example-html sentence sentence)
                         (tildify-test--example-html sentence with-nbsp))))
@@ -81,7 +81,7 @@ after `tildify-buffer' is run."
 (ert-deftest tildify-test-xml ()
   "Tests tildification in an XML document"
   (let* ((sentence (tildify-test--example-sentence " "))
-         (with-nbsp (tildify-test--example-sentence "&#160;")))
+         (with-nbsp (tildify-test--example-sentence " ")))
     (tildify-test--test '(nxml-mode)
                         (tildify-test--example-html sentence sentence t)
                         (tildify-test--example-html sentence with-nbsp t))))