aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichal Nazarewicz2014-11-16 18:08:36 +0100
committerMichal Nazarewicz2014-11-18 00:48:04 +0100
commitd5ec102b7aa0aa07bdd44ecd0b471275511fed7e (patch)
tree0ccba75832253f253930dfdec7f39cf457fb9b05
parentb8104090075eb28dd6680cc9f8b0a49674ca369a (diff)
downloademacs-d5ec102b7aa0aa07bdd44ecd0b471275511fed7e.tar.gz
emacs-d5ec102b7aa0aa07bdd44ecd0b471275511fed7e.zip
tildify.el: introduce a `tildify-pattern' variable
* textmodes/tildify.el (tildify-pattern): New variable for defining tildifying pattern. Being a buffer-local variable it is much easier to handle than `tildify-pattern-alist' that has been used so far. It also works better with derived modes. (tildify-pattern-alist): Mark as obsolete.
-rw-r--r--etc/NEWS4
-rw-r--r--lisp/ChangeLog14
-rw-r--r--lisp/textmodes/tildify.el54
3 files changed, 45 insertions, 27 deletions
diff --git a/etc/NEWS b/etc/NEWS
index d03ce7cc873..61d1cd773b0 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -301,8 +301,8 @@ use PDF instead of DVI.
301By default, 32 spaces and four TABs are considered to be too much but 301By 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 304** tildify: `tildify-space-string' and `tildify-pattern' variables added making
305`tildify-string-alist' obsolete. 305`tildify-string-alist' and `tildify-pattern-alist' obsolete.
306 306
307** Obsolete packages 307** Obsolete packages
308 308
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 33d341f8351..f5bd5273366 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,11 +1,13 @@
12014-11-17 Michal Nazarewicz <mina86@mina86.com> 12014-11-17 Michal Nazarewicz <mina86@mina86.com>
2 2
3 * textmodes/tildify.el (tildify-space-string): New variable for 3 * textmodes/tildify.el (tildify-pattern, tildify-space-string):
4 specifying representation of a hard space -- a no-break space by 4 New variables for specifying tildify pattern and representation of
5 default. Being a buffer-local variable it is much easier to 5 a hard space -- a no-break space by default -- respectively.
6 handle than `tildify-string-alist' that has been used so far. It 6 Being buffer-local they are much easier to handle than
7 also works better with derived modes. 7 `tildify-string-alist' and `tildify-pattern-alist' respectively
8 (tildify-string-alist): Mark as obsolete. 8 that have been used so far. They also works better with derived
9 modes.
10 (tildify-pattern, tildify-string-alist): Mark as obsolete.
9 11
10 * textmodes/tex-mode.el (tex-common-initialization): Set 12 * textmodes/tex-mode.el (tex-common-initialization): Set
11 `tildify-space-string' variable in all variants of TeX mode since 13 `tildify-space-string' variable in all variants of TeX mode since
diff --git a/lisp/textmodes/tildify.el b/lisp/textmodes/tildify.el
index 865dcecbecc..600696836c4 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.5 7;; Version: 4.5.6
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.
@@ -56,8 +56,21 @@
56 :version "21.1" 56 :version "21.1"
57 :group 'wp) 57 :group 'wp)
58 58
59(defcustom tildify-pattern-alist 59(defcustom tildify-pattern
60 '((t "\\([,:;(][ \t]*[a]\\|\\<[AIKOSUVZikosuvz]\\)\\([ \t]+\\|[ \t]*\n[ \t]*\\)\\(\\w\\|[([{\\]\\|<[a-zA-Z]\\)" 2)) 60 "\\(?:[,:;(][ \t]*[a]\\|\\<[AIKOSUVZikosuvz]\\)\\([ \t]+\\|[ \t]*\n[ \t]*\\)\\(?:\\w\\|[([{\\]\\|<[a-zA-Z]\\)"
61 "A pattern specifying where to insert hard spaces.
62
63`tildify-buffer' function will replace first capturing group of the regexp with
64a hard space (as defined by `tildify-space-string' variable). (Hint: \\(…\\)
65non-capturing groups can be used for grouping prior to the part of the regexp
66matching the white space). The pattern is matched case-sensitive regardless of
67the value of `case-fold-search' setting."
68 :version "25.1"
69 :group 'tildify
70 :type 'string
71 :safe t)
72
73(defcustom tildify-pattern-alist ()
61 "Alist specifying where to insert hard spaces. 74 "Alist specifying where to insert hard spaces.
62 75
63Each alist item is of the form (MAJOR-MODE REGEXP NUMBER) or 76Each alist item is of the form (MAJOR-MODE REGEXP NUMBER) or
@@ -85,6 +98,7 @@ mode, the item for the mode SYMBOL is looked up in the alist instead."
85 regexp 98 regexp
86 (integer :tag "Group ")) 99 (integer :tag "Group "))
87 (symbol :tag "Like other"))))) 100 (symbol :tag "Like other")))))
101(make-obsolete-variable 'tildify-pattern-alist 'tildify-pattern "25.1")
88 102
89(defcustom tildify-space-string "\u00A0" 103(defcustom tildify-space-string "\u00A0"
90 "Representation of a hard (a.k.a. no-break) space in current major mode. 104 "Representation of a hard (a.k.a. no-break) space in current major mode.
@@ -115,8 +129,7 @@ MAJOR-MODE defines major mode, for which the item applies. It can be either:
115 alist item 129 alist item
116 130
117STRING defines the hard space, which is inserted at places defined by 131STRING defines the hard space, which is inserted at places defined by
118`tildify-pattern-alist'. For example it can be \"~\" for TeX or \"&nbsp;\" 132`tildify-pattern'. For example it can be \"~\" for TeX or \"&nbsp;\" for SGML.
119for SGML.
120 133
121The form (MAJOR-MODE . SYMBOL) defines alias item for MAJOR-MODE. For this 134The form (MAJOR-MODE . SYMBOL) defines alias item for MAJOR-MODE. For this
122mode, the item for the mode SYMBOL is looked up in the alist instead." 135mode, the item for the mode SYMBOL is looked up in the alist instead."
@@ -204,7 +217,7 @@ END-REGEX defines end of the corresponding text part and can be either:
204;;;###autoload 217;;;###autoload
205(defun tildify-region (beg end &optional dont-ask) 218(defun tildify-region (beg end &optional dont-ask)
206 "Add hard spaces in the region between BEG and END. 219 "Add hard spaces in the region between BEG and END.
207See variables `tildify-pattern-alist', `tildify-space-string', and 220See variables `tildify-pattern', `tildify-space-string', and
208`tildify-ignored-environments-alist' for information about configuration 221`tildify-ignored-environments-alist' for information about configuration
209parameters. 222parameters.
210This function performs no refilling of the changed text. 223This function performs no refilling of the changed text.
@@ -225,7 +238,7 @@ won't be prompted for confirmation of each substitution."
225;;;###autoload 238;;;###autoload
226(defun tildify-buffer (&optional dont-ask) 239(defun tildify-buffer (&optional dont-ask)
227 "Add hard spaces in the current buffer. 240 "Add hard spaces in the current buffer.
228See variables `tildify-pattern-alist', `tildify-space-string', and 241See variables `tildify-pattern', `tildify-space-string', and
229`tildify-ignored-environments-alist' for information about configuration 242`tildify-ignored-environments-alist' for information about configuration
230parameters. 243parameters.
231This function performs no refilling of the changed text. 244This function performs no refilling of the changed text.
@@ -311,18 +324,21 @@ replacements done and response is one of symbols: t (all right), nil
311(quit), force (replace without further questions)." 324(quit), force (replace without further questions)."
312 (save-excursion 325 (save-excursion
313 (goto-char beg) 326 (goto-char beg)
314 (let* ((alist (tildify--pick-alist-entry tildify-pattern-alist)) 327 (let ((regexp tildify-pattern)
315 (regexp (car alist)) 328 (match-number 1)
316 (match-number (cadr alist)) 329 (tilde (or (tildify--pick-alist-entry tildify-string-alist)
317 (tilde (or (tildify--pick-alist-entry tildify-string-alist) 330 tildify-space-string))
318 tildify-space-string)) 331 (end-marker (copy-marker end))
319 (end-marker (copy-marker end)) 332 answer
320 answer 333 bad-answer
321 bad-answer 334 replace
322 replace 335 quit
323 quit 336 (message-log-max nil)
324 (message-log-max nil) 337 (count 0))
325 (count 0)) 338 ;; For the time being, tildify-pattern-alist overwrites tildify-pattern
339 (let ((alist (tildify--pick-alist-entry tildify-pattern-alist)))
340 (when alist
341 (setq regexp (car alist) match-number (cadr alist))))
326 (while (and (not quit) 342 (while (and (not quit)
327 (re-search-forward regexp (marker-position end-marker) t)) 343 (re-search-forward regexp (marker-position end-marker) t))
328 (when (or (not ask) 344 (when (or (not ask)