unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Michal Nazarewicz <mina86@mina86.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: 18730@debbugs.gnu.org
Subject: bug#18730: [PATCH 2/3] tildify.el: introduce a `tildify-pattern' variable
Date: Mon, 17 Nov 2014 16:41:09 +0100	[thread overview]
Message-ID: <1416238870-31725-2-git-send-email-mina86@mina86.com> (raw)
In-Reply-To: <1416238870-31725-1-git-send-email-mina86@mina86.com>

Deprecate `tildify-pattern-alist' variable in favour of a new
`tildify-pattern' variable.  Like with `tildify-space-string'
this makes the whole code simpler; as soon as the deprecated
variable is dropped that is.
---
 etc/NEWS                  |  4 ++--
 lisp/textmodes/tildify.el | 54 ++++++++++++++++++++++++++++++-----------------
 2 files changed, 37 insertions(+), 21 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index 838a800..955aa7f 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -298,8 +298,8 @@ 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.
+** tildify: `tildify-space-string' and `tildify-pattern' variables added making
+`tildify-string-alist' and `tildify-pattern-alist' obsolete.
 
 ** Obsolete packages
 
diff --git a/lisp/textmodes/tildify.el b/lisp/textmodes/tildify.el
index 865dcec..6006968 100644
--- a/lisp/textmodes/tildify.el
+++ b/lisp/textmodes/tildify.el
@@ -4,7 +4,7 @@
 
 ;; Author:     Milan Zamazal <pdm@zamazal.org>
 ;;             Michal Nazarewicz <mina86@mina86.com>
-;; Version:    4.5.5
+;; Version:    4.5.6
 ;; Keywords:   text, TeX, SGML, wp
 
 ;; This file is part of GNU Emacs.
@@ -56,8 +56,21 @@
   :version "21.1"
   :group 'wp)
 
-(defcustom tildify-pattern-alist
-  '((t "\\([,:;(][ \t]*[a]\\|\\<[AIKOSUVZikosuvz]\\)\\([ \t]+\\|[ \t]*\n[ \t]*\\)\\(\\w\\|[([{\\]\\|<[a-zA-Z]\\)" 2))
+(defcustom tildify-pattern
+  "\\(?:[,:;(][ \t]*[a]\\|\\<[AIKOSUVZikosuvz]\\)\\([ \t]+\\|[ \t]*\n[ \t]*\\)\\(?:\\w\\|[([{\\]\\|<[a-zA-Z]\\)"
+  "A pattern specifying where to insert hard spaces.
+
+`tildify-buffer' function will replace first capturing group of the regexp with
+a hard space (as defined by `tildify-space-string' variable).  (Hint: \\(…\\)
+non-capturing groups can be used for grouping prior to the part of the regexp
+matching the white space).  The pattern is matched case-sensitive regardless of
+the value of `case-fold-search' setting."
+  :version "25.1"
+  :group 'tildify
+  :type 'string
+  :safe t)
+
+(defcustom tildify-pattern-alist ()
   "Alist specifying where to insert hard spaces.
 
 Each 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."
                                        regexp
                                        (integer :tag "Group "))
                                (symbol :tag "Like other")))))
+(make-obsolete-variable 'tildify-pattern-alist 'tildify-pattern "25.1")
 
 (defcustom tildify-space-string "\u00A0"
   "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:
   alist item
 
 STRING defines the hard space, which is inserted at places defined by
-`tildify-pattern-alist'.  For example it can be \"~\" for TeX or \"&nbsp;\"
-for SGML.
+`tildify-pattern'.  For example it can be \"~\" for TeX or \"&nbsp;\" for SGML.
 
 The form (MAJOR-MODE . SYMBOL) defines alias item for MAJOR-MODE.  For this
 mode, 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:
 ;;;###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-space-string', and
+See variables `tildify-pattern', `tildify-space-string', and
 `tildify-ignored-environments-alist' for information about configuration
 parameters.
 This function performs no refilling of the changed text.
@@ -225,7 +238,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-space-string', and
+See variables `tildify-pattern', `tildify-space-string', and
 `tildify-ignored-environments-alist' for information about configuration
 parameters.
 This function performs no refilling of the changed text.
@@ -311,18 +324,21 @@ replacements done and response is one of symbols: t (all right), nil
 (quit), force (replace without further questions)."
   (save-excursion
     (goto-char beg)
-    (let* ((alist (tildify--pick-alist-entry tildify-pattern-alist))
-	   (regexp (car alist))
-	   (match-number (cadr alist))
-	   (tilde (or (tildify--pick-alist-entry tildify-string-alist)
-	              tildify-space-string))
-	   (end-marker (copy-marker end))
-	   answer
-	   bad-answer
-	   replace
-	   quit
-	   (message-log-max nil)
-	   (count 0))
+    (let ((regexp tildify-pattern)
+          (match-number 1)
+          (tilde (or (tildify--pick-alist-entry tildify-string-alist)
+                     tildify-space-string))
+          (end-marker (copy-marker end))
+          answer
+          bad-answer
+          replace
+          quit
+          (message-log-max nil)
+          (count 0))
+      ;; For the time being, tildify-pattern-alist overwrites tildify-pattern
+      (let ((alist (tildify--pick-alist-entry tildify-pattern-alist)))
+        (when alist
+          (setq regexp (car alist) match-number (cadr alist))))
       (while (and (not quit)
 		  (re-search-forward regexp (marker-position end-marker) t))
 	(when (or (not ask)
-- 
2.1.0.rc2.206.gedb03e5






  reply	other threads:[~2014-11-17 15:41 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-15  8:01 bug#18730: [PATCH] tildify.el: Add `auto-tildify' and `auto-tildify-mode' Michal Nazarewicz
2014-10-15 14:35 ` Stefan Monnier
2014-10-16  9:34   ` Michal Nazarewicz
2014-10-16 14:03     ` Stefan Monnier
2014-10-16 14:57       ` Stefan Monnier
2014-10-16 16:07       ` Michal Nazarewicz
2014-10-16 19:39         ` Stefan Monnier
2014-10-17  8:44           ` Michal Nazarewicz
2014-10-17 13:06             ` Stefan Monnier
2014-10-22 23:19               ` Michal Nazarewicz
2014-10-24 22:51                 ` Stefan Monnier
2014-10-28 22:01                   ` bug#18730: [PATCH] tildify.el: introduce a `tildify-space-string' variable Michal Nazarewicz
2014-10-30 16:27                     ` Stefan Monnier
2014-11-03 15:59                       ` Michal Nazarewicz
2014-11-03 17:00                         ` Stefan Monnier
2014-11-17 15:41                           ` bug#18730: [PATCH 1/3] " Michal Nazarewicz
2014-11-17 15:41                             ` Michal Nazarewicz [this message]
2014-11-17 15:41                             ` bug#18730: [PATCH 3/3] tildify.el: introduce a `tildify-foreach-region-function' variable Michal Nazarewicz
2014-11-17 17:38                             ` bug#18730: [PATCH 1/3] tildify.el: introduce a `tildify-space-string' variable Stefan Monnier
2014-10-16 13:17 ` bug#18730: [PATCH] tildify.el: Add `auto-tildify' and `auto-tildify-mode' Ted Zlatanov
2014-10-16 14:16   ` Michal Nazarewicz
2014-10-16 14:55     ` Stefan Monnier
2014-10-16 17:17       ` Ted Zlatanov
2014-10-16 13:19 ` Ted Zlatanov
2014-10-16 15:34 ` bug#18730: [PATCHv2 1/2] tildify.el (tildify--pick-alist-entry): rename from tildify-mode-alist Michal Nazarewicz
2014-10-16 15:34   ` bug#18730: [PATCHv2 2/2] tildify.el: Add `auto-tildify' and `auto-tildify-mode' Michal Nazarewicz
2014-10-16 19:30   ` bug#18730: [PATCHv2 1/2] tildify.el (tildify--pick-alist-entry): rename from tildify-mode-alist Stefan Monnier
2014-11-24 14:20 ` bug#18730: [PATCH 1/2] tildify.el: Add `tildify-space' and `tildify-mode' Michal Nazarewicz
2014-11-24 14:20   ` bug#18730: [PATCH 2/2] tildify.el: Add `tildify-double-space-undos' Michal Nazarewicz
2014-12-10 17:44   ` bug#18730: [PATCH 1/2] tildify.el: Add `tildify-space' and `tildify-mode' Michal Nazarewicz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1416238870-31725-2-git-send-email-mina86@mina86.com \
    --to=mina86@mina86.com \
    --cc=18730@debbugs.gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).