unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#18730: [PATCH] tildify.el: Add `auto-tildify' and `auto-tildify-mode'.
@ 2014-10-15  8:01 Michal Nazarewicz
  2014-10-15 14:35 ` Stefan Monnier
                   ` (4 more replies)
  0 siblings, 5 replies; 30+ messages in thread
From: Michal Nazarewicz @ 2014-10-15  8:01 UTC (permalink / raw)
  To: 18730; +Cc: Milan Zamazal

The `auto-tildify' function can be used as
a `post-self-insert-hook' to automatically convert spaces into
hard spaces.  It is configured via two new customize variables:
`auto-tildify-pattern-alist' and `auto-tildify-check-envs'.

`auto-tildify-mode' makes use of that function to enable
eletric behaviour of space character.
---
 etc/NEWS                        |  6 +++
 lisp/textmodes/tildify.el       | 96 ++++++++++++++++++++++++++++++++++++++++-
 test/automated/tildify-tests.el | 32 ++++++++++++++
 3 files changed, 133 insertions(+), 1 deletion(-)

diff --git a/etc/NEWS b/etc/NEWS
index e336ff5..7ef73a4 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -254,6 +254,12 @@ These emulations of old editors are believed to be no longer relevant
 \f
 * New Modes and Packages in Emacs 25.1
 
+** `auto-tildify-mode' allows to automatically add hard spaces as one types
+the text.  Breaking line after a single-character words are forbidden
+by Czech and Polish typography (and may be discouraged in other
+languages), so `auto-tildify-mode' makes it easier to create
+a typographically-correct documents.
+
 \f
 * Incompatible Lisp Changes in Emacs 25.1
 
diff --git a/lisp/textmodes/tildify.el b/lisp/textmodes/tildify.el
index 50fee2f..aed060a 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.3
+;; Version:    4.6
 ;; Keywords:   text, TeX, SGML, wp
 
 ;; This file is part of GNU Emacs.
@@ -344,6 +344,100 @@ replacements done and response is one of symbols: t (all right), nil
                         (t t))))))
 
 
+;;; *** Auto Tildify ***
+
+(defcustom auto-tildify-pattern-alist
+  '((t . "[,:;(][ \t]*[a]\\|\\<[AIKOSUVWZikosuvwz]"))
+  "Alist specifying whether to insert hard space at point.
+
+Each alist item is of the form (MAJOR-MODE . REGEXP) or
+\(MAJOR-MODE . SYMBOL).
+
+MAJOR-MODE defines major mode, for which the item applies.  It can be either:
+- a symbol equal to the major mode of the buffer to be fixed
+- t for default item, this applies to all major modes not defined in another
+  alist item
+
+REGEXP is a regular expression matching the part of a text that
+needs a hard space to be inserted instead of a space.  The regexp
+is always case sensitive, regardless of the current
+`case-fold-search' setting.
+
+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."
+  :group 'tildify
+  :type '(repeat (cons (choice (const  :tag "Default" t)
+                               (symbol :tag "For mode "))
+                       (choice (regexp :tag "Regexp   ")
+                               (symbol :tag "Like mode")))))
+
+(defcustom auto-tildify-check-envs t
+  "Should `auto-tildify' check if point is inside ignored environment."
+  :group 'tildify
+  :type 'boolean)
+
+
+;;;###autoload
+(defun auto-tildify ()
+  "Convert space before point into a hard space if the context is right.
+
+If
+ * character before point is a space character,
+ * character before that has “w” character syntax (i.e. it's
+   a word constituent),
+ * pattern from `auto-tildify-pattern-alist' matches when
+   `looking-back' (no more than 10 characters) from before the space
+   character, and
+ * `auto-tildify-check-envs' is nil or point is not inside of an
+   environment to ignore
+replace the space character with a hard space defined in
+`auto-tildify-string'.
+
+Return t if conversion happened, nil otherwise.
+
+This function is meant to be used as a `post-self-insert-hook'."
+  (interactive)
+  (let ((p (point)) case-fold-search space pattern)
+    (when (and (> (- p (point-min)) 2)
+               (eq (preceding-char) ?\s)
+               (eq (char-syntax (char-before (1- p))) ?w)
+               (setq space (tildify-mode-alist tildify-string-alist))
+               (not (string-equal " " space))
+               (setq pattern (tildify-mode-alist auto-tildify-pattern-alist))
+               (save-excursion
+                 (goto-char (1- p))
+                 (looking-back pattern (max (point-min) (- p 10))))
+               (or (not auto-tildify-check-envs)
+                   (catch 'found
+                     (tildify-foreach-region-outside-env (- p 2) (1- p)
+                       (lambda (beg end) (throw 'found t))))))
+      (delete-char -1)
+      (insert space)
+      t)))
+
+;;;###autoload
+(define-minor-mode auto-tildify-mode
+  "Adds electric behaviour to space character.
+
+When space is inserted into a buffer in a position where hard
+space is required instead, that space character is replaced by
+a hard space correct for given mode.
+
+Converting of the space is done by `auto-tildify'."
+  nil " ~" nil
+  (when auto-tildify-mode
+    (when (let ((space (tildify-mode-alist tildify-string-alist)))
+            (or (not space) (string-equal " " space)))
+      (message "Hard space for %s is a single space character, auto-tildify won't have any effect." major-mode)
+      (setq auto-tildify-mode nil))
+    (when (not (tildify-mode-alist auto-tildify-pattern-alist))
+      (message "No auto-pattern defined for %s, auto-tildify won't have any effect." major-mode)
+      (setq auto-tildify-mode nil)))
+  (if auto-tildify-mode
+      (add-hook 'post-self-insert-hook 'auto-tildify nil t)
+    (remove-hook 'post-self-insert-hook 'auto-tildify t)))
+
+
 ;;; *** Announce ***
 
 (provide 'tildify)
diff --git a/test/automated/tildify-tests.el b/test/automated/tildify-tests.el
index 53c2e62..f8a4d8c 100644
--- a/test/automated/tildify-tests.el
+++ b/test/automated/tildify-tests.el
@@ -132,6 +132,38 @@ latter is missing, SENTENCE will be used in all placeholder positions."
       (should (string-equal "close-foo" (tildify-find-env beg-re pairs))))))
 
 
+(defun auto-tildify-test--test (modes nbsp env-open)
+  (with-temp-buffer
+    (dolist (mode modes)
+      (erase-buffer)
+      (funcall mode)
+      (let ((header (concat "Testing `auto-tildify' in "
+                            (symbol-name mode) "\n")))
+        (insert header "Lorem v ")
+        (should (auto-tildify))
+        (should (string-equal (concat header "Lorem v" nbsp) (buffer-string))))
+      (erase-buffer)
+      (let ((header (concat "Testing `auto-tildify' in "
+                            (symbol-name mode) "\n")))
+        (insert header env-open "Lorem v ")
+        (should (not (auto-tildify)))
+        (should (string-equal (concat header env-open "Lorem v ")
+                              (buffer-string)))))))
+
+(ert-deftest auto-tildify-test-html ()
+  "Tests auto-tildification in an HTML document"
+  (auto-tildify-test--test '(html-mode sgml-mode) "&nbsp;" "<pre>"))
+
+(ert-deftest auto-tildify-test-xml ()
+  "Tests auto-tildification in an XML document"
+  (auto-tildify-test--test '(nxml-mode) "&#160;" "<! -- "))
+
+(ert-deftest auto-tildify-test-tex ()
+  "Tests tildification in a TeX document"
+  (auto-tildify-test--test '(tex-mode latex-mode plain-tex-mode)
+                           "~" "\\verb# "))
+
+
 (provide 'tildify-tests)
 
 ;;; tildify-tests.el ends here





^ permalink raw reply related	[flat|nested] 30+ messages in thread

* bug#18730: [PATCH] tildify.el: Add `auto-tildify' and `auto-tildify-mode'.
  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 13:17 ` bug#18730: [PATCH] tildify.el: Add `auto-tildify' and `auto-tildify-mode' Ted Zlatanov
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 30+ messages in thread
From: Stefan Monnier @ 2014-10-15 14:35 UTC (permalink / raw)
  To: Michal Nazarewicz; +Cc: Milan Zamazal, 18730

Hi Michal,

Thanks for your patch.  It looks like a good feature.  See some
comments below.


        Stefan


> It is configured via two new customize variables:
> `auto-tildify-pattern-alist' and `auto-tildify-check-envs'.

Could it use the existing tildify-pattern-alist?

> +Breaking line after a single-character words are forbidden
> +by Czech and Polish typography (and may be discouraged in other
> +languages), so `auto-tildify-mode' makes it easier to create
> +a typographically-correct documents.

Indeed, that's why we have fill-single-char-nobreak-p.  You might like
to write the above text is such a way to make it clear what's the
difference between the two.

> +  "Alist specifying whether to insert hard space at point.

IIUC this isn't quite right: "insert hard space" would imply adding
a space without changing anything else, whereas what you code does is to
replace a soft space by a hard space.  So instead of "insert hard", I'd
say maybe "harden".

> +;;;###autoload
> +(defun auto-tildify ()
[...]
> +This function is meant to be used as a `post-self-insert-hook'."

Why is it autoloaded?  Are users expected to add it to
post-self-insert-hook by hand?

> +  (interactive)

Why is it interactive?  Would it make sense to bind it to a key sequence
or to run it via M-x ?

> +;;;###autoload
> +(define-minor-mode auto-tildify-mode

I recommend you name it just `tildify-mode' (and generally just use
a "tildify-" prefix rather than "auto-tildify-").
For that, it would most likely make sense to rename tildify-mode-alist
(e.g. to tildify--mode-alist, tho another name could be even better
since this name doesn't actually say what it does).

> +      (message "Hard space for %s is a single space character, auto-tildify won't have any effect." major-mode)

Please try to stay within the limits of 80 columns.





^ permalink raw reply	[flat|nested] 30+ messages in thread

* bug#18730: [PATCH] tildify.el: Add `auto-tildify' and `auto-tildify-mode'.
  2014-10-15 14:35 ` Stefan Monnier
@ 2014-10-16  9:34   ` Michal Nazarewicz
  2014-10-16 14:03     ` Stefan Monnier
  0 siblings, 1 reply; 30+ messages in thread
From: Michal Nazarewicz @ 2014-10-16  9:34 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Milan Zamazal, 18730

>> It is configured via two new customize variables:
>> `auto-tildify-pattern-alist' and `auto-tildify-check-envs'.

On Wed, Oct 15 2014, Stefan Monnier wrote:
> Could it use the existing tildify-pattern-alist?

In the current implementation those two have to be a separate alists.
tildify-pattern-alist assumes that the whole text is available so the
patterns may check text before and after the soft space.  Patterns in
auto-tildify-pattern-alist can only look back before the space
character.

The implementation could be changed to use tildify-pattern-alist but:

* It will be slower because it would have to match pattern after every
  inserted character (whereas currently the pattern is matched only if
  character at point is space and character before it is a word
  character).

* It will be less intuitive because text “far” behind a cursor will
  change, e.g. (^ denotes point):

      Foo Bar a ^

  and then after pressing “x” (_ denotes hard space):

      Foo Bar a_x^

* Furthermore, it might be hard/impossible to manually replace hard
  space with a soft space if user desires to do so.

>> +Breaking line after a single-character words are forbidden
>> +by Czech and Polish typography (and may be discouraged in other
>> +languages), so `auto-tildify-mode' makes it easier to create
>> +a typographically-correct documents.
>
> Indeed, that's why we have fill-single-char-nobreak-p.  You might like
> to write the above text is such a way to make it clear what's the
> difference between the two.

Would this be better:

** `tildify-mode' automatically hardens spaces as one types the text.
Breaking line after a single-character words is forbidden by Czech and Polish
typography.  `auto-tildify-mode' makes creating a typographically-correct markup
in formats such as HTML, LaTeX, Markdown, etc.

-- 
Best regards,                                         _     _
.o. | Liege of Serenely Enlightened Majesty of      o' \,=./ `o
..o | Computer Science,  Michał “mina86” Nazarewicz    (o o)
ooo +--<mpn@google.com>--<xmpp:mina86@jabber.org>--ooO--(_)--Ooo--





^ permalink raw reply	[flat|nested] 30+ messages in thread

* bug#18730: [PATCH] tildify.el: Add `auto-tildify' and `auto-tildify-mode'.
  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 13:17 ` Ted Zlatanov
  2014-10-16 14:16   ` Michal Nazarewicz
  2014-10-16 13:19 ` Ted Zlatanov
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 30+ messages in thread
From: Ted Zlatanov @ 2014-10-16 13:17 UTC (permalink / raw)
  To: Michal Nazarewicz; +Cc: Milan Zamazal, 18730

On Wed, 15 Oct 2014 10:01:26 +0200 Michal Nazarewicz <mina86@mina86.com> wrote: 
MN> +** `auto-tildify-mode' allows to automatically add hard spaces as one types
MN> +the text.  Breaking line after a single-character words are forbidden
MN> +by Czech and Polish typography (and may be discouraged in other
MN> +languages), so `auto-tildify-mode' makes it easier to create
MN> +a typographically-correct documents.

The name is kind of opaque, I expected it to do with tildes like the "~"
character or maybe home directories but it's actually about typography.

As a suggestion, could it be a general `auto-typography-mode' with
options, one of which would be
`typography-no-linebreak-after-single-character-word'?  Similar to how
`whitespace-mode' works?  There surely are other such typography
options.

Ted





^ permalink raw reply	[flat|nested] 30+ messages in thread

* bug#18730: [PATCH] tildify.el: Add `auto-tildify' and `auto-tildify-mode'.
  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 13:17 ` bug#18730: [PATCH] tildify.el: Add `auto-tildify' and `auto-tildify-mode' 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-11-24 14:20 ` bug#18730: [PATCH 1/2] tildify.el: Add `tildify-space' and `tildify-mode' Michal Nazarewicz
  4 siblings, 0 replies; 30+ messages in thread
From: Ted Zlatanov @ 2014-10-16 13:19 UTC (permalink / raw)
  To: Michal Nazarewicz; +Cc: Milan Zamazal, 18730

Another followup: it would be nice if `auto-{tildify,typography}-mode'
worked with `fill-paragraph' as well. I don't think it will, as
proposed (but haven't tested it).

Ted





^ permalink raw reply	[flat|nested] 30+ messages in thread

* bug#18730: [PATCH] tildify.el: Add `auto-tildify' and `auto-tildify-mode'.
  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
  0 siblings, 2 replies; 30+ messages in thread
From: Stefan Monnier @ 2014-10-16 14:03 UTC (permalink / raw)
  To: Michal Nazarewicz; +Cc: Milan Zamazal, 18730

>> Could it use the existing tildify-pattern-alist?
> In the current implementation those two have to be a separate alists.
> tildify-pattern-alist assumes that the whole text is available so the
> patterns may check text before and after the soft space.  Patterns in
> auto-tildify-pattern-alist can only look back before the space
> character.

Is there a particular reason we can't use tildify-pattern-alist anyway
(and look both before *and* after)?

Or recognize the entries of tildify-pattern-alist which can't be used
(e.g. make sure that the char modified is the one right before point)?

> The implementation could be changed to use tildify-pattern-alist but:
> * It will be slower because it would have to match pattern after every
>   inserted character (whereas currently the pattern is matched only if
>   character at point is space and character before it is a word
>   character).

Why?  Can't we just check (eq last-command-event ?\s)?

> * Furthermore, it might be hard/impossible to manually replace hard
>   space with a soft space if user desires to do so.

That's a very important consideration, indeed.

> Would this be better:
> ** `tildify-mode' automatically hardens spaces as one types the text.
> Breaking line after a single-character words is forbidden by Czech and Polish
> typography.  `auto-tildify-mode' makes creating a typographically-correct markup
> in formats such as HTML, LaTeX, Markdown, etc.

Oh, yes, now that's more clear.  There's an "easier" missing in the last
sentence, tho.  You can add it as "... makes it easier to create ...".
And there's an "auto-" that needs to be removed.


        Stefan





^ permalink raw reply	[flat|nested] 30+ messages in thread

* bug#18730: [PATCH] tildify.el: Add `auto-tildify' and `auto-tildify-mode'.
  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
  0 siblings, 1 reply; 30+ messages in thread
From: Michal Nazarewicz @ 2014-10-16 14:16 UTC (permalink / raw)
  To: Ted Zlatanov; +Cc: Milan Zamazal, 18730

On Thu, Oct 16 2014, Ted Zlatanov <tzz@lifelogs.com> wrote:
> On Wed, 15 Oct 2014 10:01:26 +0200 Michal Nazarewicz <mina86@mina86.com> wrote: 
> MN> +** `auto-tildify-mode' allows to automatically add hard spaces as one types
> MN> +the text.  Breaking line after a single-character words are forbidden
> MN> +by Czech and Polish typography (and may be discouraged in other
> MN> +languages), so `auto-tildify-mode' makes it easier to create
> MN> +a typographically-correct documents.
>
> The name is kind of opaque, I expected it to do with tildes like the "~"
> character or maybe home directories but it's actually about
> typography.

The name, as I understand it, is historical because in the past it
indeed had to do with tildes.  In TeX (and LaTeX) tilde denotes
a non-breaking space.

I agree that the name may be confusing, but the mode has been around for
years, so changing the name now may be not worth it.

> As a suggestion, could it be a general `auto-typography-mode' with
> options, one of which would be
> `typography-no-linebreak-after-single-character-word'?  Similar to how
> `whitespace-mode' works?  There surely are other such typography
> options.

The way I see it, tildify is for fixing soft spaces, so perhaps a better
option would be to add a whitespace-mode style for that?

In particular, tildify is a bit heavy-weight as it implements
environment (or context) checking (e.g. checking if one is inside of
<pre> in HTML or inside of \begin{math} in LaTeX), which may be too slow
for whitespace-mode.  I don't have experience with fontifying though.

On Thu, Oct 16 2014, Ted Zlatanov <tzz@lifelogs.com> wrote:
> Another followup: it would be nice if `auto-{tildify,typography}-mode'
> worked with `fill-paragraph' as well. I don't think it will, as
> proposed (but haven't tested it).

There is, somewhat unrelated, fill-single-char-nobreak-p predicated:

  (when (fboundp 'fill-single-char-nobreak-p)
    (add-hook 'fill-nobreak-predicate 'fill-single-char-nobreak-p))

Again, it's much simpler than tildify since it does not check context,
but the way I see it is that one would use fill-paragraph for text that
needs to be formatted in source, while tildify is for cases where the
source is interpreted and rendered (like HTML where new lines are
treated the same way spaces are so how fill-paragraph fills does not
matter).

-- 
Best regards,                                         _     _
.o. | Liege of Serenely Enlightened Majesty of      o' \,=./ `o
..o | Computer Science,  Michał “mina86” Nazarewicz    (o o)
ooo +--<mpn@google.com>--<xmpp:mina86@jabber.org>--ooO--(_)--Ooo--





^ permalink raw reply	[flat|nested] 30+ messages in thread

* bug#18730: [PATCH] tildify.el: Add `auto-tildify' and `auto-tildify-mode'.
  2014-10-16 14:16   ` Michal Nazarewicz
@ 2014-10-16 14:55     ` Stefan Monnier
  2014-10-16 17:17       ` Ted Zlatanov
  0 siblings, 1 reply; 30+ messages in thread
From: Stefan Monnier @ 2014-10-16 14:55 UTC (permalink / raw)
  To: Michal Nazarewicz; +Cc: Milan Zamazal, Ted Zlatanov, 18730

> I agree that the name may be confusing, but the mode has been around for
> years, so changing the name now may be not worth it.

Agreed.  We can think of a better name, but that's a separate concern.

> The way I see it, tildify is for fixing soft spaces, so perhaps a better
> option would be to add a whitespace-mode style for that?

whitespace is already too much of a monster for my taste.  So unless
"tildification" can be added in a modular way to whitespace, I think
we're better off with it being separate.


        Stefan





^ permalink raw reply	[flat|nested] 30+ messages in thread

* bug#18730: [PATCH] tildify.el: Add `auto-tildify' and `auto-tildify-mode'.
  2014-10-16 14:03     ` Stefan Monnier
@ 2014-10-16 14:57       ` Stefan Monnier
  2014-10-16 16:07       ` Michal Nazarewicz
  1 sibling, 0 replies; 30+ messages in thread
From: Stefan Monnier @ 2014-10-16 14:57 UTC (permalink / raw)
  To: Michal Nazarewicz; +Cc: Milan Zamazal, 18730

> Is there a particular reason we can't use tildify-pattern-alist anyway
> (and look both before *and* after)?
> Or recognize the entries of tildify-pattern-alist which can't be used
> (e.g. make sure that the char modified is the one right before point)?

Just to clarify: I don't think we should do heroic efforts to merge
tildify-pattern-alist and auto-tildify-pattern-alist, but if we can
avoid the duplication in a "simple enough" way, I think we should.


        Stefan





^ permalink raw reply	[flat|nested] 30+ messages in thread

* bug#18730: [PATCHv2 1/2] tildify.el (tildify--pick-alist-entry): rename from tildify-mode-alist.
  2014-10-15  8:01 bug#18730: [PATCH] tildify.el: Add `auto-tildify' and `auto-tildify-mode' Michal Nazarewicz
                   ` (2 preceding siblings ...)
  2014-10-16 13:19 ` Ted Zlatanov
@ 2014-10-16 15:34 ` 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
  4 siblings, 2 replies; 30+ messages in thread
From: Michal Nazarewicz @ 2014-10-16 15:34 UTC (permalink / raw)
  To: Stefan Monnier, 18730; +Cc: Milan Zamazal

tildify-mode-alist does not really describe what the functino does so
rename it to tildify--pick-alist-entry.  This also makes it clear that
the function is an internal one.
---
 lisp/textmodes/tildify.el | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/lisp/textmodes/tildify.el b/lisp/textmodes/tildify.el
index 50fee2f..91f5a38 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.3
+;; Version:    4.5.4
 ;; Keywords:   text, TeX, SGML, wp
 
 ;; This file is part of GNU Emacs.
@@ -226,13 +226,13 @@ won't be prompted for confirmation of each substitution."
 
 ;;; *** Auxiliary functions ***
 
-(defun tildify-mode-alist (mode-alist &optional mode)
+(defun tildify--pick-alist-entry (mode-alist &optional mode)
   "Return alist item for the MODE-ALIST in the current major MODE."
   (let ((alist (cdr (or (assoc (or mode major-mode) mode-alist)
 			(assoc t mode-alist)))))
     (if (and alist
 	     (symbolp alist))
-	(tildify-mode-alist mode-alist alist)
+	(tildify--pick-alist-entry mode-alist alist)
       alist)))
 
 (defun tildify-foreach-region-outside-env (beg end callback)
@@ -244,7 +244,7 @@ arguments specifying the region to operate on.  Stop scanning the
 region as soon as CALLBACK returns nil.  Environments to ignore
 are determined from `tildify-ignored-environments-alist'."
   (declare (indent 2))
-  (let ((pairs (tildify-mode-alist tildify-ignored-environments-alist)))
+  (let ((pairs (tildify--pick-alist-entry tildify-ignored-environments-alist)))
     (if (not pairs)
         (funcall callback beg end)
       (let ((func (lambda (b e)
@@ -300,10 +300,10 @@ 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-mode-alist tildify-pattern-alist))
+    (let* ((alist (tildify--pick-alist-entry tildify-pattern-alist))
 	   (regexp (car alist))
 	   (match-number (cadr alist))
-	   (tilde (tildify-mode-alist tildify-string-alist))
+	   (tilde (tildify--pick-alist-entry tildify-string-alist))
 	   (end-marker (copy-marker end))
 	   answer
 	   bad-answer
-- 
2.1.0.rc2.206.gedb03e5






^ permalink raw reply related	[flat|nested] 30+ messages in thread

* bug#18730: [PATCHv2 2/2] tildify.el: Add `auto-tildify' and `auto-tildify-mode'.
  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   ` 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
  1 sibling, 0 replies; 30+ messages in thread
From: Michal Nazarewicz @ 2014-10-16 15:34 UTC (permalink / raw)
  To: Stefan Monnier, 18730; +Cc: Milan Zamazal

The `auto-tildify' function can be used as
a `post-self-insert-hook' to automatically convert spaces into
hard spaces.  It is configured via two new customize variables:
`auto-tildify-pattern-alist' and `auto-tildify-check-envs'.

`auto-tildify-mode' makes use of that function to enable
eletric behaviour of space character.
---
 etc/NEWS                        |  5 +++
 lisp/textmodes/tildify.el       | 96 ++++++++++++++++++++++++++++++++++++++++-
 test/automated/tildify-tests.el | 32 ++++++++++++++
 3 files changed, 132 insertions(+), 1 deletion(-)

diff --git a/etc/NEWS b/etc/NEWS
index 36f1d9d..b6d4055 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -269,6 +269,11 @@ These emulations of old editors are believed to be no longer relevant
 \f
 * New Modes and Packages in Emacs 25.1
 
+** `tildify-mode' automatically hardens spaces as one types the text.
+Breaking line after a single-character words is forbidden by Czech and Polish
+typography.  `tildify-mode' makes creating a typographically-correct markup in
+formats such as HTML, LaTeX, Markdown, etc.
+
 \f
 * Incompatible Lisp Changes in Emacs 25.1
 
diff --git a/lisp/textmodes/tildify.el b/lisp/textmodes/tildify.el
index 91f5a38..33067a6 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.4
+;; Version:    4.6
 ;; Keywords:   text, TeX, SGML, wp
 
 ;; This file is part of GNU Emacs.
@@ -344,6 +344,100 @@ replacements done and response is one of symbols: t (all right), nil
                         (t t))))))
 
 
+;;; *** Auto Tildify ***
+
+(defcustom tildify-space-pattern-alist
+  '((t . "[,:;(][ \t]*[a]\\|\\<[AIKOSUVWZikosuvwz]"))
+  "Alist specifying whether a hard space is required at point.
+
+Each alist item is of the form (MAJOR-MODE . REGEXP) or
+\(MAJOR-MODE . SYMBOL).
+
+MAJOR-MODE defines major mode, for which the item applies.  It can be either:
+- a symbol equal to the major mode of the buffer to be fixed
+- t for default item, this applies to all major modes not defined in another
+  alist item
+
+REGEXP is a regular expression matching the part of a text that
+needs a hard space to be inserted instead of a space.  The regexp
+is always case sensitive, regardless of the current
+`case-fold-search' setting.
+
+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."
+  :group 'tildify
+  :type '(repeat (cons (choice (const  :tag "Default" t)
+                               (symbol :tag "For mode "))
+                       (choice (regexp :tag "Regexp   ")
+                               (symbol :tag "Like mode")))))
+
+(defcustom tildify-space-check-envs t
+  "Should `tildify-space' check if point is inside ignored environment."
+  :group 'tildify
+  :type 'boolean)
+
+
+(defun tildify-space ()
+  "Convert space before point into a hard space if the context is right.
+
+If
+ * character before point is a space character,
+ * character before that has “w” character syntax (i.e. it's a word
+   constituent),
+ * pattern from `tildify-space-pattern-alist' matches when `looking-back' (no
+   more than 10 characters) from before the space character, and
+ * `tildify-space-check-envs' is nil or point is not inside of an environment to
+   ignore
+replace the space character with a hard space specified in
+`tildify-string-alist'.
+
+Return t if conversion happened, nil otherwise.
+
+This function is meant to be used as a `post-self-insert-hook'."
+  (let ((p (point)) case-fold-search space pattern)
+    (when (and (> (- p (point-min)) 2)
+               (eq (preceding-char) ?\s)
+               (eq (char-syntax (char-before (1- p))) ?w)
+               (setq space (tildify--pick-alist-entry tildify-string-alist))
+               (not (string-equal " " space))
+               (setq pattern (tildify--pick-alist-entry
+                              tildify-space-pattern-alist))
+               (save-excursion
+                 (goto-char (1- p))
+                 (looking-back pattern (max (point-min) (- p 10))))
+               (or (not tildify-space-check-envs)
+                   (catch 'found
+                     (tildify-foreach-region-outside-env (- p 2) (1- p)
+                       (lambda (beg end) (throw 'found t))))))
+      (delete-char -1)
+      (insert space)
+      t)))
+
+;;;###autoload
+(define-minor-mode tildify-mode
+  "Adds electric behaviour to space character.
+
+When space is inserted into a buffer in a position where hard
+space is required instead, that space character is replaced by
+a hard space correct for given mode.
+
+Converting of the space is done by `tildify-space'."
+  nil " ~" nil
+  (when tildify-mode
+    (when (let ((space (tildify--pick-alist-entry tildify-string-alist)))
+            (or (not space) (string-equal " " space)))
+      (message (concat "Hard space for %s is a single space character, "
+                       "tildify won't have any effect.") major-mode)
+      (setq tildify-mode nil))
+    (when (not (tildify--pick-alist-entry tildify-space-pattern-alist))
+      (message (concat "No pattern defined for %s, "
+                       "tildify won't have any effect.") major-mode)
+      (setq tildify-mode nil)))
+  (if tildify-mode
+      (add-hook 'post-self-insert-hook 'tildify-space nil t)
+    (remove-hook 'post-self-insert-hook 'tildify-space t)))
+
+
 ;;; *** Announce ***
 
 (provide 'tildify)
diff --git a/test/automated/tildify-tests.el b/test/automated/tildify-tests.el
index 53c2e62..7ba270a 100644
--- a/test/automated/tildify-tests.el
+++ b/test/automated/tildify-tests.el
@@ -132,6 +132,38 @@ latter is missing, SENTENCE will be used in all placeholder positions."
       (should (string-equal "close-foo" (tildify-find-env beg-re pairs))))))
 
 
+(defun tildify-space-test--test (modes nbsp env-open)
+  (with-temp-buffer
+    (dolist (mode modes)
+      (erase-buffer)
+      (funcall mode)
+      (let ((header (concat "Testing `tildify-space' in "
+                            (symbol-name mode) "\n")))
+        (insert header "Lorem v ")
+        (should (tildify-space))
+        (should (string-equal (concat header "Lorem v" nbsp) (buffer-string))))
+      (erase-buffer)
+      (let ((header (concat "Testing `tildify-space' in "
+                            (symbol-name mode) "\n")))
+        (insert header env-open "Lorem v ")
+        (should (not (tildify-space)))
+        (should (string-equal (concat header env-open "Lorem v ")
+                              (buffer-string)))))))
+
+(ert-deftest tildify-space-test-html ()
+  "Tests auto-tildification in an HTML document"
+  (tildify-space-test--test '(html-mode sgml-mode) "&nbsp;" "<pre>"))
+
+(ert-deftest tildify-space-test-xml ()
+  "Tests auto-tildification in an XML document"
+  (tildify-space-test--test '(nxml-mode) "&#160;" "<! -- "))
+
+(ert-deftest tildify-space-test-tex ()
+  "Tests tildification in a TeX document"
+  (tildify-space-test--test '(tex-mode latex-mode plain-tex-mode)
+                           "~" "\\verb# "))
+
+
 (provide 'tildify-tests)
 
 ;;; tildify-tests.el ends here
-- 
2.1.0.rc2.206.gedb03e5






^ permalink raw reply related	[flat|nested] 30+ messages in thread

* bug#18730: [PATCH] tildify.el: Add `auto-tildify' and `auto-tildify-mode'.
  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
  1 sibling, 1 reply; 30+ messages in thread
From: Michal Nazarewicz @ 2014-10-16 16:07 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Milan Zamazal, 18730

On Thu, Oct 16 2014, Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>>> Could it use the existing tildify-pattern-alist?
>> In the current implementation those two have to be a separate alists.
>> tildify-pattern-alist assumes that the whole text is available so the
>> patterns may check text before and after the soft space.  Patterns in
>> auto-tildify-pattern-alist can only look back before the space
>> character.
>
> Is there a particular reason we can't use tildify-pattern-alist anyway
> (and look both before *and* after)?
>
> Or recognize the entries of tildify-pattern-alist which can't be used
> (e.g. make sure that the char modified is the one right before point)?

No, because with the default pattern, it won't be the character before
point that is being changed.

You can create a buffer, set latex-mode, and insert "Foo v bar v "
(i.e. with trailing space at the end) and you'll see that when you run
`tildify-buffer') the space after first v will be replaced, but the
final one won't.

So with automatic tildifying, the space will be hardened only after some
word-character is inserted after the final space.

>> The implementation could be changed to use tildify-pattern-alist but:
>> * It will be slower because it would have to match pattern after every
>>   inserted character (whereas currently the pattern is matched only if
>>   character at point is space and character before it is a word
>>   character).
>
> Why?  Can't we just check (eq last-command-event ?\s)?

We cannot, see above.

Of course, we can change `tildify-pattern-alist''s default value and
require that it does not look past the white-space that is being
replaced, in which case auto-tildify will be able to use it.  I would be
fine with that myself, but I don't know how strict should we be about
backward compatibility.

-- 
Best regards,                                         _     _
.o. | Liege of Serenely Enlightened Majesty of      o' \,=./ `o
..o | Computer Science,  Michał “mina86” Nazarewicz    (o o)
ooo +--<mpn@google.com>--<xmpp:mina86@jabber.org>--ooO--(_)--Ooo--





^ permalink raw reply	[flat|nested] 30+ messages in thread

* bug#18730: [PATCH] tildify.el: Add `auto-tildify' and `auto-tildify-mode'.
  2014-10-16 14:55     ` Stefan Monnier
@ 2014-10-16 17:17       ` Ted Zlatanov
  0 siblings, 0 replies; 30+ messages in thread
From: Ted Zlatanov @ 2014-10-16 17:17 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Milan Zamazal, 18730, Michal Nazarewicz

On Thu, 16 Oct 2014 10:55:08 -0400 Stefan Monnier <monnier@iro.umontreal.ca> wrote: 

>> I agree that the name may be confusing, but the mode has been around for
>> years, so changing the name now may be not worth it.

SM> Agreed.  We can think of a better name, but that's a separate concern.

All right. Thanks for explaining Michal, I didn't know the origin. I am
OK with leaving it as you proposed.

Ted





^ permalink raw reply	[flat|nested] 30+ messages in thread

* bug#18730: [PATCHv2 1/2] tildify.el (tildify--pick-alist-entry): rename from tildify-mode-alist.
  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   ` Stefan Monnier
  1 sibling, 0 replies; 30+ messages in thread
From: Stefan Monnier @ 2014-10-16 19:30 UTC (permalink / raw)
  To: Michal Nazarewicz; +Cc: Milan Zamazal, 18730

> tildify-mode-alist does not really describe what the functino does so
> rename it to tildify--pick-alist-entry.  This also makes it clear that
> the function is an internal one.

Looks good, please install,


        Stefan





^ permalink raw reply	[flat|nested] 30+ messages in thread

* bug#18730: [PATCH] tildify.el: Add `auto-tildify' and `auto-tildify-mode'.
  2014-10-16 16:07       ` Michal Nazarewicz
@ 2014-10-16 19:39         ` Stefan Monnier
  2014-10-17  8:44           ` Michal Nazarewicz
  0 siblings, 1 reply; 30+ messages in thread
From: Stefan Monnier @ 2014-10-16 19:39 UTC (permalink / raw)
  To: Michal Nazarewicz; +Cc: Milan Zamazal, 18730

> Of course, we can change `tildify-pattern-alist''s default value and
> require that it does not look past the white-space that is being
> replaced, in which case auto-tildify will be able to use it.  I would be
> fine with that myself, but I don't know how strict should we be about
> backward compatibility.

OK, that sounds fine:

Introduce a new variable that can be used by tildify-mode.  It would
probably work similarly to your auto-tildify-pattern-alist *except* that
it won't be an alist indexed by the major-mode.
Instead, the major-modes should set this var buffer-locally if they want
it to be different.

Please try to make it so that this new var can also be used for
tildify-region, move the current default entry in tildify-pattern-alist
to it (so that tildify-pattern-alist defaults to nil), and mark
tildify-pattern-alist as obsolete.

tildify-string-alist should also be made obsolete and replaced by
a variable which is set buffer-locally by the major-modes.

Could that work?


        Stefan





^ permalink raw reply	[flat|nested] 30+ messages in thread

* bug#18730: [PATCH] tildify.el: Add `auto-tildify' and `auto-tildify-mode'.
  2014-10-16 19:39         ` Stefan Monnier
@ 2014-10-17  8:44           ` Michal Nazarewicz
  2014-10-17 13:06             ` Stefan Monnier
  0 siblings, 1 reply; 30+ messages in thread
From: Michal Nazarewicz @ 2014-10-17  8:44 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Milan Zamazal, 18730

On Thu, Oct 16 2014, Stefan Monnier <monnier@iro.umontreal.ca> wrote:
> Introduce a new variable that can be used by tildify-mode.  […]
>
> Please try to make it so that this new var can also be used for
> tildify-region, move the current default entry in tildify-pattern-alist
> to it (so that tildify-pattern-alist defaults to nil), and mark
> tildify-pattern-alist as obsolete.

I think those two need to be separate but the default for tildify-region
can be based on the one used by tildify-mode.  I.e. if tildify-mode uses
tildify-space-regex than the default for tildify-region would be

  (concat tildify-space-regex
          "\\(\\s-+\\)\\([ \t]*\n[ \t]*\\|[ \t]+\\)"
          "[\\w([{]")

> tildify-string-alist should also be made obsolete and replaced by
> a variable which is set buffer-locally by the major-modes.

So how would that work?  Would I have to also add setting of
tildify-string (or perhaps tildify-hard-space would be a better name)
variable in all major modes that tildify-string-alist now includes?  Or
add hooks in tildify?

-- 
Best regards,                                         _     _
.o. | Liege of Serenely Enlightened Majesty of      o' \,=./ `o
..o | Computer Science,  Michał “mina86” Nazarewicz    (o o)
ooo +--<mpn@google.com>--<xmpp:mina86@jabber.org>--ooO--(_)--Ooo--





^ permalink raw reply	[flat|nested] 30+ messages in thread

* bug#18730: [PATCH] tildify.el: Add `auto-tildify' and `auto-tildify-mode'.
  2014-10-17  8:44           ` Michal Nazarewicz
@ 2014-10-17 13:06             ` Stefan Monnier
  2014-10-22 23:19               ` Michal Nazarewicz
  0 siblings, 1 reply; 30+ messages in thread
From: Stefan Monnier @ 2014-10-17 13:06 UTC (permalink / raw)
  To: Michal Nazarewicz; +Cc: Milan Zamazal, 18730

> So how would that work?  Would I have to also add setting of
> tildify-string (or perhaps tildify-hard-space would be a better name)
> variable in all major modes that tildify-string-alist now includes?

Yes, that's how it should work.


        Stefan





^ permalink raw reply	[flat|nested] 30+ messages in thread

* bug#18730: [PATCH] tildify.el: Add `auto-tildify' and `auto-tildify-mode'.
  2014-10-17 13:06             ` Stefan Monnier
@ 2014-10-22 23:19               ` Michal Nazarewicz
  2014-10-24 22:51                 ` Stefan Monnier
  0 siblings, 1 reply; 30+ messages in thread
From: Michal Nazarewicz @ 2014-10-22 23:19 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Milan Zamazal, 18730

On Fri, Oct 17 2014, Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>> So how would that work?  Would I have to also add setting of
>> tildify-string (or perhaps tildify-hard-space would be a better name)
>> variable in all major modes that tildify-string-alist now includes?
>
> Yes, that's how it should work.

So I came up with a patch whose excerpt is:

------ >8 --------------------------------------------------------------
diff --git a/lisp/textmodes/tex-mode.el b/lisp/textmodes/tex-mode.el
index bc10eab..446cdd4 100644
--- a/lisp/textmodes/tex-mode.el
+++ b/lisp/textmodes/tex-mode.el
@@ -1206,6 +1206,8 @@ Entering SliTeX mode runs the hook `text-mode-hook', then the hook
 (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 hard-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,
diff --git a/lisp/textmodes/tildify.el b/lisp/textmodes/tildify.el
index 91f5a38..9f9e472 100644
--- a/lisp/textmodes/tildify.el
+++ b/lisp/textmodes/tildify.el
@@ -86,17 +86,29 @@ mode, the item for the mode SYMBOL is looked up in the alist instead."
                                        (integer :tag "Group "))
                                (symbol :tag "Like other")))))
 
+(defcustom hard-space-string nil
+  "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 "No hard-space representation")
+                 (const  :tag "No-break space (U+00A0)" "\u00A0")
+                 (string :tag "Custom string"))
+  :safe t)
+
 (defcustom tildify-string-alist
------ >8 --------------------------------------------------------------

but now compilation fails with:

textmodes/tex-mode.el:1210:15:Warning: assignment to free variable
    `hard-space-string'

Requiring tildify in tex-mode (and other affected modes) seems a bit of
an overkill.  Am I doing something stupid here?  Or would moving the
local variable to another file?

-- 
Best regards,                                         _     _
.o. | Liege of Serenely Enlightened Majesty of      o' \,=./ `o
..o | Computer Science,  Michał “mina86” Nazarewicz    (o o)
ooo +--<mpn@google.com>--<xmpp:mina86@jabber.org>--ooO--(_)--Ooo--





^ permalink raw reply related	[flat|nested] 30+ messages in thread

* bug#18730: [PATCH] tildify.el: Add `auto-tildify' and `auto-tildify-mode'.
  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
  0 siblings, 1 reply; 30+ messages in thread
From: Stefan Monnier @ 2014-10-24 22:51 UTC (permalink / raw)
  To: Michal Nazarewicz; +Cc: Milan Zamazal, 18730

> --- a/lisp/textmodes/tildify.el
> +++ b/lisp/textmodes/tildify.el
> @@ -86,17 +86,29 @@ mode, the item for the mode SYMBOL is looked up in the alist instead."
>                                         (integer :tag "Group "))
>                                 (symbol :tag "Like other")))))
> 
> +(defcustom hard-space-string nil

As long as it's in tildify.el it should have a "tildify-" prefix.

> but now compilation fails with:

> textmodes/tex-mode.el:1210:15:Warning: assignment to free variable
>     `hard-space-string'

That's not a failure, just a warning.

> Requiring tildify in tex-mode (and other affected modes) seems a bit of
> an overkill.  Am I doing something stupid here?

No, you're doing it right.  You should just add a (defvar
hard-space-string) to tex-mode.el to silence the compiler warning.


        Stefan





^ permalink raw reply	[flat|nested] 30+ messages in thread

* bug#18730: [PATCH] tildify.el: introduce a `tildify-space-string' variable
  2014-10-24 22:51                 ` Stefan Monnier
@ 2014-10-28 22:01                   ` Michal Nazarewicz
  2014-10-30 16:27                     ` Stefan Monnier
  0 siblings, 1 reply; 30+ messages in thread
From: Michal Nazarewicz @ 2014-10-28 22:01 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Milan Zamazal, 18730

Deprecate `tildify-string-alist' variable and instead introduce
a new `tildify-space-string' variable.  The alist was somehow
complicated to use, both for users and in code, and did not work
correctly with derived modes.  Instead of trying to make its
handling even more complicated to fix the latter problem, replace
it with `tildify-space-string' buffer-local variable.
---
 etc/NEWS                        |  3 +++
 lisp/nxml/nxml-mode.el          |  9 +++++++++
 lisp/textmodes/sgml-mode.el     |  9 +++++++++
 lisp/textmodes/tex-mode.el      |  4 ++++
 lisp/textmodes/tildify.el       | 38 ++++++++++++++++++++++++++------------
 test/automated/tildify-tests.el |  2 +-
 6 files changed, 52 insertions(+), 13 deletions(-)

On Fri, Oct 24 2014, Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>> --- a/lisp/textmodes/tildify.el
>> +++ b/lisp/textmodes/tildify.el
>> @@ -86,17 +86,29 @@ mode, the item for the mode SYMBOL is looked up in the alist instead."
>>                                         (integer :tag "Group "))
>>                                 (symbol :tag "Like other")))))
>> 
>> +(defcustom hard-space-string nil
>
> As long as it's in tildify.el it should have a "tildify-" prefix.

Yeah, I was hoping I could find some more generic place for the variable
to live in, but couldn't in the end.  Renamed to tildify-space-string.

>> but now compilation fails with:
>
>> textmodes/tex-mode.el:1210:15:Warning: assignment to free variable
>>     `hard-space-string'
>
> That's not a failure, just a warning.

Ah, yes, I missed an unrelated compilation error.

diff --git a/etc/NEWS b/etc/NEWS
index 8bb4f41..02f2085 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -263,6 +263,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
 
 ---
diff --git a/lisp/nxml/nxml-mode.el b/lisp/nxml/nxml-mode.el
index 4859bbc..a1472b5 100644
--- a/lisp/nxml/nxml-mode.el
+++ b/lisp/nxml/nxml-mode.el
@@ -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]
@@ -504,6 +506,13 @@ be treated as a single markup item, set the variable
 
 Many aspects this mode can be customized using
 \\[customize-group] nxml RET."
+  ;; If encoding allows use non-break space character as hard space, otherwise
+  ;; use numeric entity (since XML does not define &nbsp;).
+  (setq-local tildify-space-string
+              (if (memq (coding-system-change-eol-conversion
+                         buffer-file-coding-system nil)
+                        (find-coding-systems-string " "))
+                  " " "&#160;"))
   ;; (kill-all-local-variables)
   (set (make-local-variable 'mode-line-process) '((nxml-degraded "/degraded")))
   ;; We'll determine the fill prefix ourselves
diff --git a/lisp/textmodes/sgml-mode.el b/lisp/textmodes/sgml-mode.el
index 39ac062..d7d82a8 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'.
 	 (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 allows use non-break space character as hard space, otherwise
+  ;; use numeric entity (so we don't depend on &nbsp; being defined).
+  (setq-local tildify-space-string
+              (if (memq (coding-system-change-eol-conversion
+                         buffer-file-coding-system nil)
+                        (find-coding-systems-string " "))
+                  " " "&#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
diff --git a/lisp/textmodes/tex-mode.el b/lisp/textmodes/tex-mode.el
index bc10eab..0cfc0cf 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
   (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,
diff --git a/lisp/textmodes/tildify.el b/lisp/textmodes/tildify.el
index 91f5a38..0c092b3 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.4
+;; Version:    4.5.5
 ;; Keywords:   text, TeX, SGML, wp
 
 ;; This file is part of GNU Emacs.
@@ -86,17 +86,29 @@ mode, the item for the mode SYMBOL is looked up in the alist instead."
                                        (integer :tag "Group "))
                                (symbol :tag "Like other")))))
 
+(defcustom tildify-space-string nil
+  "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 "No hard-space representation")
+                 (const  :tag "No-break space (U+00A0)" "\u00A0")
+                 (string :tag "Custom string"))
+  :safe t)
+
 (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 . " "))
+  '()
   "Alist specifying what is a hard space in the current major mode.
 
+This variable is deprecated in favour of `tildify-space-string'
+variable and takes effect only if `tildify-space-string' is not set.
+
 Each alist item is of the form (MAJOR-MODE . STRING) or
 \(MAJOR-MODE . SYMBOL).
 
@@ -193,7 +205,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 +226,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 +315,9 @@ 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-space-string
+		      (tildify--pick-alist-entry tildify-string-alist)
+		      " "))
 	   (end-marker (copy-marker end))
 	   answer
 	   bad-answer
diff --git a/test/automated/tildify-tests.el b/test/automated/tildify-tests.el
index 53c2e62..e532cf0 100644
--- a/test/automated/tildify-tests.el
+++ b/test/automated/tildify-tests.el
@@ -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))))
-- 
2.1.0.rc2.206.gedb03e5





^ permalink raw reply related	[flat|nested] 30+ messages in thread

* bug#18730: [PATCH] tildify.el: introduce a `tildify-space-string' variable
  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
  0 siblings, 1 reply; 30+ messages in thread
From: Stefan Monnier @ 2014-10-30 16:27 UTC (permalink / raw)
  To: Michal Nazarewicz; +Cc: Milan Zamazal, 18730

> Deprecate `tildify-string-alist' variable and instead introduce
> a new `tildify-space-string' variable.  The alist was somehow
> complicated to use, both for users and in code, and did not work
> correctly with derived modes.  Instead of trying to make its
> handling even more complicated to fix the latter problem, replace
> it with `tildify-space-string' buffer-local variable.

The patch looks good.  Please install it with an appropriate ChangeLog
entry (and of course, the same text used as commit message).
See comments below,


        Stefan


> +  ;; If encoding allows use non-break space character as hard space, otherwise
> +  ;; use numeric entity (so we don't depend on &nbsp; being defined).

You might like to add a FIXME in there deploring the fact that nxml-mode
doesn't derive from sgml-mode, which would save us from duplicating this code.

> +  (setq-local tildify-space-string
> +              (if (memq (coding-system-change-eol-conversion
> +                         buffer-file-coding-system nil)
> +                        (find-coding-systems-string " "))

Hmm... I would have used something more like

   (equal " " (decode-coding-string (encode-coding-string
                                     " " buffer-file-coding-system)
                                    buffer-file-coding-system))

> +(defcustom tildify-space-string nil

I think you could use " " as the default value so you can assume the var
only holds a string.

> -    (sgml-mode . "&nbsp;")
> -    (html-mode . sgml-mode)

The new code uses "&#160" for those instead.  Is this change on purpose?

> +This variable is deprecated in favour of `tildify-space-string'
> +variable and takes effect only if `tildify-space-string' is not set.

Then add a (make-obsolete-variable 'tildify-string-alist
'tildify-space-string' "25.1").
And then check C-h v tildify-string-alist RET since the obsolescence info
in there will make part of the above text redundant.

> +	   (tilde (or tildify-space-string
> +		      (tildify--pick-alist-entry tildify-string-alist)
> +		      " "))

Since tildify-string-alist defaults to nil, I would make it take
precedence over tildify-space-string.


        Stefan





^ permalink raw reply	[flat|nested] 30+ messages in thread

* bug#18730: [PATCH] tildify.el: introduce a `tildify-space-string' variable
  2014-10-30 16:27                     ` Stefan Monnier
@ 2014-11-03 15:59                       ` Michal Nazarewicz
  2014-11-03 17:00                         ` Stefan Monnier
  0 siblings, 1 reply; 30+ messages in thread
From: Michal Nazarewicz @ 2014-11-03 15:59 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 18730

>> +(defcustom tildify-space-string nil

On Thu, Oct 30 2014, Stefan Monnier wrote:
> I think you could use " " as the default value so you can assume the var
> only holds a string.

I'm slightly afraid of using no-break space since it may confuse people
who use incompatible encodings.  Should I just go ahead with it anyway
and have Emacs deal with encodings once user attempts to save the file?

>> -    (sgml-mode . "&nbsp;")
>> -    (html-mode . sgml-mode)
>
> The new code uses "&#160" for those instead.  Is this change on purpose?

Yes.  This slightly changes observable behaviour but I feel that most
users won't even notice it since they will end up using \u00A0 and for
the rest it might prevent some subtle problems where &nbsp; is not
defined in XML or XHTML.

-- 
Best regards,                                         _     _
.o. | Liege of Serenely Enlightened Majesty of      o' \,=./ `o
..o | Computer Science,  Michał “mina86” Nazarewicz    (o o)
ooo +--<mpn@google.com>--<xmpp:mina86@jabber.org>--ooO--(_)--Ooo--





^ permalink raw reply	[flat|nested] 30+ messages in thread

* bug#18730: [PATCH] tildify.el: introduce a `tildify-space-string' variable
  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
  0 siblings, 1 reply; 30+ messages in thread
From: Stefan Monnier @ 2014-11-03 17:00 UTC (permalink / raw)
  To: Michal Nazarewicz; +Cc: 18730

>>> +(defcustom tildify-space-string nil
> On Thu, Oct 30 2014, Stefan Monnier wrote:
>> I think you could use " " as the default value so you can assume the var
>> only holds a string.
> I'm slightly afraid of using no-break space since it may confuse people
> who use incompatible encodings.

Such encodings are pretty rare, I think.

> Should I just go ahead with it anyway and have Emacs deal with
> encodings once user attempts to save the file?

Yes.

> Yes.  This slightly changes observable behaviour but I feel that most
> users won't even notice it since they will end up using \u00A0 and for
> the rest it might prevent some subtle problems where &nbsp; is not
> defined in XML or XHTML.

As an XHTML user, I'd prefer seeing &nbsp; over some numerical constant,
so if there's a way to auto-detect when it can be used, that's
even better.  But feel free to install your patch with &#160; and keep
the &nbsp; for "maybe if I find the time later".


        Stefan





^ permalink raw reply	[flat|nested] 30+ messages in thread

* bug#18730: [PATCH 1/3] tildify.el: introduce a `tildify-space-string' variable
  2014-11-03 17:00                         ` Stefan Monnier
@ 2014-11-17 15:41                           ` Michal Nazarewicz
  2014-11-17 15:41                             ` bug#18730: [PATCH 2/3] tildify.el: introduce a `tildify-pattern' variable Michal Nazarewicz
                                               ` (2 more replies)
  0 siblings, 3 replies; 30+ messages in thread
From: Michal Nazarewicz @ 2014-11-17 15:41 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 18730

Deprecate `tildify-string-alist' variable and instead introduce
a new `tildify-space-string' variable.  The alist was somehow
complicated to use, both for users and in code, and did not work
correctly with derived modes.  Instead of trying to make its
handling even more complicated, replace it with
`tildify-space-string' variable that is set as a buffer-local
variable in plain-tex, sgml and nxml modes.
---
 etc/NEWS                        |  3 +++
 lisp/nxml/nxml-mode.el          | 10 ++++++++++
 lisp/textmodes/sgml-mode.el     |  9 +++++++++
 lisp/textmodes/tex-mode.el      |  4 ++++
 lisp/textmodes/tildify.el       | 38 +++++++++++++++++++++++++-------------
 test/automated/tildify-tests.el |  4 ++--
 6 files changed, 53 insertions(+), 15 deletions(-)

On Mon, Nov 03 2014, Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>> I'm slightly afraid of using no-break space since it may confuse people
>> who use incompatible encodings.
>
> Such encodings are pretty rare, I think.
>
>> Should I just go ahead with it anyway and have Emacs deal with
>> encodings once user attempts to save the file?
>
> Yes.

Changed the code to default to no-break space.

> As an XHTML user, I'd prefer seeing &nbsp; over some numerical constant,
> so if there's a way to auto-detect when it can be used, that's
> even better.  But feel free to install your patch with &#160; and keep
> the &nbsp; for "maybe if I find the time later".

Added a FIXME.

You gave a thumbs up for this patch already, but it had a few
modifications and I wanted to mail it in the context of the next two
patches to get a final ack.

diff --git a/etc/NEWS b/etc/NEWS
index 4282dc5..838a800 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -298,6 +298,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
 
 ---
diff --git a/lisp/nxml/nxml-mode.el b/lisp/nxml/nxml-mode.el
index 4859bbc..47f8066 100644
--- a/lisp/nxml/nxml-mode.el
+++ b/lisp/nxml/nxml-mode.el
@@ -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)
diff --git a/lisp/textmodes/sgml-mode.el b/lisp/textmodes/sgml-mode.el
index 39ac062..9d1cb03 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'.
 	 (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
diff --git a/lisp/textmodes/tex-mode.el b/lisp/textmodes/tex-mode.el
index bc10eab..0cfc0cf 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
   (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,
diff --git a/lisp/textmodes/tildify.el b/lisp/textmodes/tildify.el
index 91f5a38..865dcec 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.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
diff --git a/test/automated/tildify-tests.el b/test/automated/tildify-tests.el
index 53c2e62..e532cf0 100644
--- a/test/automated/tildify-tests.el
+++ b/test/automated/tildify-tests.el
@@ -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))))
-- 
2.1.0.rc2.206.gedb03e5






^ permalink raw reply related	[flat|nested] 30+ messages in thread

* bug#18730: [PATCH 2/3] tildify.el: introduce a `tildify-pattern' variable
  2014-11-17 15:41                           ` bug#18730: [PATCH 1/3] " Michal Nazarewicz
@ 2014-11-17 15:41                             ` Michal Nazarewicz
  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
  2 siblings, 0 replies; 30+ messages in thread
From: Michal Nazarewicz @ 2014-11-17 15:41 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 18730

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






^ permalink raw reply related	[flat|nested] 30+ messages in thread

* bug#18730: [PATCH 3/3] tildify.el: introduce a `tildify-foreach-region-function' variable
  2014-11-17 15:41                           ` bug#18730: [PATCH 1/3] " Michal Nazarewicz
  2014-11-17 15:41                             ` bug#18730: [PATCH 2/3] tildify.el: introduce a `tildify-pattern' variable Michal Nazarewicz
@ 2014-11-17 15:41                             ` Michal Nazarewicz
  2014-11-17 17:38                             ` bug#18730: [PATCH 1/3] tildify.el: introduce a `tildify-space-string' variable Stefan Monnier
  2 siblings, 0 replies; 30+ messages in thread
From: Michal Nazarewicz @ 2014-11-17 15:41 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 18730

The `tildify-foreach-region-function' variable is a function which
will allow major modes (or users) to create a more elaborate
environment filtering functions rather than just a simple set of
regular expressions.  Furthermore since major modes already know how
to parse contents of the buffer, the custom made function should be
much faster.

The variable is set to `tildify--deprecated-ignore-evironments'
function by default which interprets the now deprecated
`tildify-ignored-environments-alist' variable.  It is, however,
overwritten in tex-mode, sgml-mode, and nxml-mode.  The consequence of
that is user-costomisation of the deprecated variable for those modes
will no longer work, and users will have to change
`tildify-foreach-region-function' variable directly.

A new `tildify-foreach-ignore-environments' function makes it rather
easy to convert existing customisation of the alist variable into
customisation of the function variable.
---
 etc/NEWS                        |   7 +-
 lisp/nxml/nxml-mode.el          |   6 ++
 lisp/textmodes/sgml-mode.el     |  15 ++++
 lisp/textmodes/tex-mode.el      |  19 +++++
 lisp/textmodes/tildify.el       | 175 +++++++++++++++++++++++-----------------
 test/automated/tildify-tests.el |  61 +++++++++++++-
 6 files changed, 204 insertions(+), 79 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index 955aa7f..3753d2c 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -298,8 +298,11 @@ 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' and `tildify-pattern' variables added making
-`tildify-string-alist' and `tildify-pattern-alist' obsolete.
+** tildify: `tildify-space-string', `tildify-pattern', and
+`tildify-foreach-region-function' variables added making
+`tildify-string-alist', `tildify-pattern-alist', and
+`tildify-ignored-environments-alist' variables (as well as a few
+helper functions) obsolete.
 
 ** Obsolete packages
 
diff --git a/lisp/nxml/nxml-mode.el b/lisp/nxml/nxml-mode.el
index 47f8066..b198f4a 100644
--- a/lisp/nxml/nxml-mode.el
+++ b/lisp/nxml/nxml-mode.el
@@ -450,6 +450,7 @@ reference.")
       (rng-validate-while-idle (current-buffer)))))
 
 (defvar tildify-space-string)
+(defvar tildify-foreach-region-function)
 
 ;;;###autoload
 (define-derived-mode nxml-mode text-mode "nXML"
@@ -515,6 +516,11 @@ Many aspects this mode can be customized using
                           (encode-coding-string " " buffer-file-coding-system)
                           buffer-file-coding-system) " ")
                   " " "&#160;"))
+  ;; FIXME: Use the fact that we're parsing the document already
+  ;; rather than using regex-based filtering.
+  (setq-local tildify-foreach-region-function
+              (apply-partially 'tildify-foreach-ignore-environments
+                               '(("<! *--" . "-- *>") ("<" . ">"))))
   (set (make-local-variable 'mode-line-process) '((nxml-degraded "/degraded")))
   ;; We'll determine the fill prefix ourselves
   (make-local-variable 'adaptive-fill-mode)
diff --git a/lisp/textmodes/sgml-mode.el b/lisp/textmodes/sgml-mode.el
index 9d1cb03..73b5292 100644
--- a/lisp/textmodes/sgml-mode.el
+++ b/lisp/textmodes/sgml-mode.el
@@ -457,6 +457,7 @@ This function is designed for use in `fill-nobreak-predicate'.
 	 (eq (char-before) ?<))))
 
 (defvar tildify-space-string)
+(defvar tildify-foreach-region-function)
 
 ;;;###autoload
 (define-derived-mode sgml-mode text-mode '(sgml-xml-mode "XML" "SGML")
@@ -486,6 +487,20 @@ Do \\[describe-key] on the following bindings to discover what they do.
                           (encode-coding-string " " buffer-file-coding-system)
                           buffer-file-coding-system) " ")
                   " " "&#160;"))
+  ;; FIXME: Use the fact that we're parsing the document already
+  ;; rather than using regex-based filtering.
+  (setq-local tildify-foreach-region-function
+              (apply-partially
+               'tildify-foreach-ignore-environments
+               `((,(eval-when-compile
+                     (concat
+                      "<\\("
+                      (regexp-opt '("pre" "dfn" "code" "samp" "kbd" "var"
+                                    "PRE" "DFN" "CODE" "SAMP" "KBD" "VAR"))
+                      "\\)\\>[^>]*>"))
+                  . ("</" 1 ">"))
+                 ("<! *--" . "-- *>")
+                 ("<" . ">"))))
   ;;(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
diff --git a/lisp/textmodes/tex-mode.el b/lisp/textmodes/tex-mode.el
index 0cfc0cf..1993ff1 100644
--- a/lisp/textmodes/tex-mode.el
+++ b/lisp/textmodes/tex-mode.el
@@ -1204,12 +1204,31 @@ Entering SliTeX mode runs the hook `text-mode-hook', then the hook
   (setq tex-start-of-header "\\\\documentstyle{slides}\\|\\\\documentclass{slides}"))
 
 (defvar tildify-space-string)
+(defvar tildify-foreach-region-function)
 
 (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 "~")
+  ;; FIXME: Use the fact that we're parsing the document already
+  ;; rather than using regex-based filtering.
+  (setq-local tildify-foreach-region-function
+              (apply-partially
+               'tildify-foreach-ignore-environments
+               `(("\\\\\\\\" . "") ; do not remove this
+                 (,(eval-when-compile
+                     (concat "\\\\begin{\\("
+                             (regexp-opt '("verbatim" "math" "displaymath"
+                                           "equation" "eqnarray" "eqnarray*"))
+                             "\\)}"))
+                  . ("\\\\end{" 1 "}"))
+                 ("\\\\verb\\*?\\(.\\)" . (1))
+                 ("\\$\\$?" . (0))
+                 ("\\\\(" . "\\\\)")
+                 ("\\\\[[]" . "\\\\[]]")
+                 ("\\\\[a-zA-Z]+\\( +\\|{}\\)[a-zA-Z]*" . "")
+                 ("%" . "$"))))
   ;; A line containing just $$ is treated as a paragraph separator.
   (setq-local paragraph-start "[ \t]*$\\|[\f\\\\%]\\|[ \t]*\\$\\$")
   ;; A line starting with $$ starts a paragraph,
diff --git a/lisp/textmodes/tildify.el b/lisp/textmodes/tildify.el
index 6006968..d935ff7 100644
--- a/lisp/textmodes/tildify.el
+++ b/lisp/textmodes/tildify.el
@@ -1,10 +1,10 @@
-;;; tildify.el --- adding hard spaces into texts
+;;; tildify.el --- adding hard spaces into texts -*- lexical-binding: t -*-
 
 ;; Copyright (C) 1997-2014 Free Software Foundation, Inc.
 
 ;; Author:     Milan Zamazal <pdm@zamazal.org>
 ;;             Michal Nazarewicz <mina86@mina86.com>
-;; Version:    4.5.6
+;; Version:    4.5.7
 ;; Keywords:   text, TeX, SGML, wp
 
 ;; This file is part of GNU Emacs.
@@ -143,36 +143,31 @@ mode, the item for the mode SYMBOL is looked up in the alist instead."
 (make-obsolete-variable 'tildify-string-alist
                         'tildify-space-string "25.1")
 
-(defcustom tildify-ignored-environments-alist
-  `((latex-mode
-     ("\\\\\\\\" . "")		; do not remove this
-     (,(eval-when-compile (concat
-                           "\\\\begin{\\("
-                           (regexp-opt '("verbatim" "math" "displaymath"
-                                         "equation" "eqnarray" "eqnarray*"))
-                           "\\)}"))
-      . ("\\\\end{" 1 "}"))
-     ("\\\\verb\\*?\\(.\\)" . (1))
-     ("\\$\\$?" . (0))
-     ("\\\\(" . "\\\\)")
-     ("\\\\[[]" . "\\\\[]]")
-     ("\\\\[a-zA-Z]+\\( +\\|{}\\)[a-zA-Z]*" . "")
-     ("%" . "$"))
-    (plain-tex-mode . latex-mode)
-    (html-mode
-     (,(eval-when-compile (concat
-                           "<\\("
-                           (regexp-opt '("pre" "dfn" "code" "samp" "kbd" "var"
-                                         "PRE" "DFN" "CODE" "SAMP" "KBD" "VAR"))
-                           "\\)\\>[^>]*>"))
-      . ("</" 1 ">"))
-     ("<! *--" . "-- *>")
-     ("<" . ">"))
-    (sgml-mode . html-mode)
-    (xml-mode
-     ("<! *--" . "-- *>")
-     ("<" . ">"))
-    (nxml-mode . xml-mode))
+(defcustom tildify-foreach-region-function
+  'tildify--deprecated-ignore-evironments
+  "A function calling a callback on portions of the buffer to tildify.
+
+The function is called from `tildify-buffer' function with three arguments: FUNC
+BEG END.  FUNC is a callback accepting two arguments -- REG-BEG REG-END --
+specifying a portion of buffer to operate on.
+
+The BEG and END arguments may be used to limit portion of the buffer being
+scanned, but the `tildify-foreach-region-function' is not required to make use
+of them.  IT must, however, terminate as soon as FUNC returns nil.
+
+For example, if `tildify-buffer' function should operate on the whole buffer,
+a simple pass through function could be used:
+    (setq-local tildify-foreach-region-function
+                (lambda (cb beg end) (funcall cb beg end)))
+or better still:
+    (setq-local tildify-foreach-region-function 'funcall)
+See `tildify-foreach-ignore-environments' function for other ways to use the
+variable."
+  :version "25.1"
+  :group 'tildify
+  :type 'function)
+
+(defcustom tildify-ignored-environments-alist ()
   "Alist specifying ignored structured text environments.
 Parts of text defined in this alist are skipped without performing hard space
 insertion on them.  These setting allow skipping text parts like verbatim or
@@ -186,13 +181,8 @@ MAJOR-MODE defines major mode, for which the item applies.  It can be either:
 - t for default item, this applies to all major modes not defined in another
   alist item
 
-BEG-REGEX is a regexp matching beginning of a text part to be skipped.
-END-REGEX defines end of the corresponding text part and can be either:
-- a regexp matching the end of the skipped text part
-- a list of regexps and numbers, which will compose the ending regexp by
-  concatenating themselves, while replacing the numbers with corresponding
-  subexpressions of BEG-REGEX (this is used to solve cases like
-  \\\\verb<character> in TeX)."
+See `tildify-foreach-ignore-environments' function for description of BEG-REGEX
+and END-REGEX."
   :group 'tildify
   :type '(repeat
           (cons :tag "Entry for major mode"
@@ -210,6 +200,8 @@ END-REGEX defines end of the corresponding text part and can be either:
                                       (choice (regexp  :tag "Regexp")
                                               (integer :tag "Group "))))))
                  (symbol :tag "Like other")))))
+(make-obsolete-variable 'tildify-ignored-environments-alist
+                        'tildify-foreach-region-function "25.1")
 
 
 ;;; *** Interactive functions ***
@@ -225,14 +217,15 @@ If DONT-ASK is set, or called interactively with prefix argument, user
 won't be prompted for confirmation of each substitution."
   (interactive "*rP")
   (let (case-fold-search (count 0) (ask (not dont-ask)))
-    (tildify-foreach-region-outside-env beg end
+    (tildify--foreach-region
       (lambda (beg end)
         (let ((aux (tildify-tildify beg end ask)))
           (setq count (+ count (car aux)))
           (if (not (eq (cdr aux) 'force))
               (cdr aux)
             (setq ask nil)
-            t))))
+            t)))
+      beg end)
     (message "%d spaces replaced." count)))
 
 ;;;###autoload
@@ -258,40 +251,76 @@ won't be prompted for confirmation of each substitution."
 	     (symbolp alist))
 	(tildify--pick-alist-entry mode-alist alist)
       alist)))
+(make-obsolete 'tildify--pick-alist-entry
+               "it should not be used in new code." "25.1")
+
+(defun tildify--deprecated-ignore-evironments (callback beg end)
+  "Call CALLBACK on regions between BEG and END.
 
-(defun tildify-foreach-region-outside-env (beg end callback)
-  "Scan region from BEG to END calling CALLBACK on portions out of environments.
-Call CALLBACK on each region outside of environment to ignore.
-CALLBACK will only be called for regions which have intersection
-with [BEG END].  It must be a function that takes two point
-arguments specifying the region to operate on.  Stop scanning the
-region as soon as CALLBACK returns nil.  Environments to ignore
-are determined from `tildify-ignored-environments-alist'."
-  (declare (indent 2))
+Call CALLBACK on each region outside of environment to ignore.  Stop scanning
+the region as soon as CALLBACK returns nil.  Environments to ignore are
+defined by deprecated `tildify-ignored-environments-alist'.   CALLBACK may be
+called on portions of the buffer outside of [BEG END)."
   (let ((pairs (tildify--pick-alist-entry tildify-ignored-environments-alist)))
-    (if (not pairs)
-        (funcall callback beg end)
-      (let ((func (lambda (b e)
-                    (let ((b (max b beg)) (e (min e end)))
-                    (if (< b e) (funcall callback b e) t))))
-            (beg-re (concat "\\(?:"
-                            (mapconcat 'car pairs "\\)\\|\\(?:")
-                            "\\)"))
-            p end-re)
-        (save-excursion
-          (save-restriction
-            (widen)
-            (goto-char (point-min))
-            (while (and (< (setq p (point)) end)
-                        (if (not (setq end-re
-                                       (tildify-find-env beg-re pairs)))
-                            (progn (funcall func p end) nil)
-                          (funcall func p (match-beginning 0))
-                          (when (< (point) end)
-                            (setq p (point))
-                            (re-search-forward end-re nil t)))))))))))
-
-(defun tildify-find-env (regexp pairs)
+    (if pairs
+        (tildify-foreach-ignore-environments pairs callback beg end)
+      (funcall callback beg end))))
+(make-obsolete 'tildify--deprecated-ignore-evironments
+               "it should not be used in new code." "25.1")
+
+(defun tildify-foreach-ignore-environments (pairs callback _beg end)
+  "Outside of environments defined by PAIRS call CALLBACK.
+
+PAIRS is a list of (BEG-REGEX . END-REGEX) cons.  BEG-REGEX is a regexp matching
+beginning of a text part to be skipped.  END-REGEX defines end of the
+corresponding text part and can be either:
+- a regexp matching the end of the skipped text part
+- a list of regexps and numbers, which will compose the ending regexp by
+  concatenating themselves, while replacing the numbers with corresponding
+  subexpressions of BEG-REGEX (this is used to solve cases like
+  \\\\verb<character> in TeX).
+
+CALLBACK is a function accepting two arguments -- REG-BEG and REG-END -- that
+will be called for portions of the buffer outside of the environments defined by
+PAIRS regexes.
+
+The function will return as soon as CALLBACK returns nil or point goes past END.
+CALLBACK may be called on portions of the buffer outside of [BEG END); in fact
+BEG argument is ignored.
+
+This function is meant to be used to set `tildify-foreach-region-function'
+variable.  For example, for an XML file one might use:
+  (setq-local tildify-foreach-region-function
+    (apply-partially 'tildify-foreach-ignore-environments
+                     '((\"<! *--\" . \"-- *>\") (\"<\" . \">\"))))"
+  (let ((beg-re (concat "\\(?:" (mapconcat 'car pairs "\\)\\|\\(?:") "\\)"))
+        p end-re)
+    (save-excursion
+      (save-restriction
+        (widen)
+        (goto-char (point-min))
+        (while (and (< (setq p (point)) end)
+                    (if (setq end-re (tildify--find-env beg-re pairs))
+                        (and (funcall callback p (match-beginning 0))
+                             (< (point) end)
+                             (re-search-forward end-re nil t))
+                      (funcall callback p end)
+                      nil)))))))
+
+(defun tildify--foreach-region (callback beg end)
+  "Call CALLBACK on portions of the buffer between BEG and END.
+
+Which portions to call CALLBACK on is determined by
+`tildify-foreach-region-function' variable.  This function merely makes sure
+CALLBACK is not called with portions of the buffer outside of [BEG END)."
+  (let ((func (lambda (reg-beg reg-end)
+                (setq reg-beg (max reg-beg beg) reg-end (min reg-end end))
+                (and (or (>= reg-beg reg-end)
+                         (funcall callback reg-beg reg-end))
+                     (< reg-end end)))))
+    (funcall tildify-foreach-region-function func beg end)))
+
+(defun tildify--find-env (regexp pairs)
   "Find environment using REGEXP.
 Return regexp for the end of the environment found in PAIRS or nil if
 no environment was found."
diff --git a/test/automated/tildify-tests.el b/test/automated/tildify-tests.el
index e532cf0..55d2d57 100644
--- a/test/automated/tildify-tests.el
+++ b/test/automated/tildify-tests.el
@@ -1,4 +1,4 @@
-;;; tildify-test.el --- ERT tests for tildify.el
+;;; tildify-test.el --- ERT tests for tildify.el -*- lexical-binding: t -*-
 
 ;; Copyright (C) 2014 Free Software Foundation, Inc.
 
@@ -117,8 +117,8 @@ latter is missing, SENTENCE will be used in all placeholder positions."
     (insert "foo whatever end-foo")
     (goto-char (point-min))
     (should (string-equal "end-foo"
-                          (tildify-find-env "foo\\|bar"
-                                            '(("foo\\|bar" . ("end-" 0))))))))
+                          (tildify--find-env "foo\\|bar"
+                                             '(("foo\\|bar" . ("end-" 0))))))))
 
 
 (ert-deftest tildify-test-find-env-group-index-bug ()
@@ -129,7 +129,60 @@ latter is missing, SENTENCE will be used in all placeholder positions."
           (beg-re "start-\\(foo\\|bar\\)\\|open-\\(foo\\|bar\\)"))
       (insert "open-foo whatever close-foo")
       (goto-char (point-min))
-      (should (string-equal "close-foo" (tildify-find-env beg-re pairs))))))
+      (should (string-equal "close-foo" (tildify--find-env beg-re pairs))))))
+
+
+(defmacro with-test-foreach (expected &rest body)
+  "Helper macro for testing foreach functions.
+BODY has access to pairs variable and called lambda."
+  (declare (indent 1))
+  (let ((got (make-symbol "got")))
+    `(with-temp-buffer
+       (insert "1 /- 2 -/ 3 V~ 4 ~ 5 /- 6 -/ 7")
+       (let* ((pairs '(("/-" . "-/") ("V\\(.\\)" . (1))))
+              (,got "")
+              (called (lambda (s e)
+                        (setq ,got (concat ,got (buffer-substring s e))))))
+         (setq-local tildify-foreach-region-function
+                     (apply-partially 'tildify-foreach-ignore-environments
+                                      pairs))
+         ,@body
+         (should (string-equal ,expected ,got))))))
+
+(ert-deftest tildify-test-foreach-ignore-environments ()
+    "Basic test of `tildify-foreach-ignore-environments'"
+  (with-test-foreach "1  3  5  7"
+    (tildify-foreach-ignore-environments pairs called (point-min) (point-max))))
+
+
+(ert-deftest tildify-test-foreach-ignore-environments-early-return ()
+    "Test whether `tildify-foreach-ignore-environments' returns early
+The function must terminate as soon as callback returns nil."
+  (with-test-foreach "1 "
+    (tildify-foreach-ignore-environments
+     pairs (lambda (start end) (funcall called start end) nil)
+     (point-min) (point-max))))
+
+(ert-deftest tildify-test-foreach-region ()
+    "Basic test of `tildify--foreach-region'"
+  (with-test-foreach "1  3  5  7"
+    (tildify--foreach-region called (point-min) (point-max))))
+
+(ert-deftest tildify-test-foreach-region-early-return ()
+    "Test whether `tildify--foreach-ignore' returns early
+The function must terminate as soon as callback returns nil."
+  (with-test-foreach "1 "
+    (tildify--foreach-region (lambda (start end) (funcall called start end) nil)
+      (point-min) (point-max))))
+
+(ert-deftest tildify-test-foreach-region-limit-region ()
+    "Test whether `tildify--foreach-ignore' limits callback to given region"
+  (with-test-foreach "3 "
+    (tildify--foreach-region called
+      (+ (point-min) 10) (+ (point-min) 16))) ; start at "3" end past "4"
+  (with-test-foreach "3  5"
+    (tildify--foreach-region called
+      (+ (point-min) 10) (+ (point-min) 20)))) ; start at "3" end past "5"
 
 
 (provide 'tildify-tests)
-- 
2.1.0.rc2.206.gedb03e5






^ permalink raw reply related	[flat|nested] 30+ messages in thread

* bug#18730: [PATCH 1/3] tildify.el: introduce a `tildify-space-string' variable
  2014-11-17 15:41                           ` bug#18730: [PATCH 1/3] " Michal Nazarewicz
  2014-11-17 15:41                             ` bug#18730: [PATCH 2/3] tildify.el: introduce a `tildify-pattern' variable Michal Nazarewicz
  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                             ` Stefan Monnier
  2 siblings, 0 replies; 30+ messages in thread
From: Stefan Monnier @ 2014-11-17 17:38 UTC (permalink / raw)
  To: Michal Nazarewicz; +Cc: 18730

> You gave a thumbs up for this patch already, but it had a few
> modifications and I wanted to mail it in the context of the next two
> patches to get a final ack.

Looks good, thanks.  But please make sure you use a ChangeLog formatted
commit message.  The other 2 patches look OK as well.


        Stefan





^ permalink raw reply	[flat|nested] 30+ messages in thread

* bug#18730: [PATCH 1/2] tildify.el: Add `tildify-space' and `tildify-mode'.
  2014-10-15  8:01 bug#18730: [PATCH] tildify.el: Add `auto-tildify' and `auto-tildify-mode' Michal Nazarewicz
                   ` (3 preceding siblings ...)
  2014-10-16 15:34 ` bug#18730: [PATCHv2 1/2] tildify.el (tildify--pick-alist-entry): rename from tildify-mode-alist Michal Nazarewicz
@ 2014-11-24 14:20 ` 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
  4 siblings, 2 replies; 30+ messages in thread
From: Michal Nazarewicz @ 2014-11-24 14:20 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 18730

* lisp/textmodes/tildify.el (tildify-space): A new function
which can be used as a `post-self-insert-hook' to automatically
convert spaces into hard spaces.
(tildify-space-pattern): A new variable specifying pattern where
`tildify-space' should take effect.
(tildify-space-predicates): A new variable specifying list of
predicate functions that all must return non-nil for
`tildify-space' to take effect.
(tildify-space-region-predicate): A new functions meant to be
used as a predicate in `tildify-space-predicates' list.
(tildify-mode): A new minor mode enabling `tildify-space' as a
`post-self-insert-hook'

* tests/automated/tildify-tests.el (tildify-space-test--test):
A new helper function for testing `tildify-space' function.
(tildify-space-test-html, tildify-space-test-html-nbsp)
(tildify-space-test-xml, tildify-space-test-tex): New tests for
`tildify-space' function.
---
 etc/NEWS                        |  6 +++
 lisp/textmodes/tildify.el       | 88 ++++++++++++++++++++++++++++++++++++++++-
 test/automated/tildify-tests.el | 38 ++++++++++++++++++
 3 files changed, 131 insertions(+), 1 deletion(-)

diff --git a/etc/NEWS b/etc/NEWS
index 5154066..0c01560 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -346,6 +346,12 @@ helper functions) obsolete.
 * New Modes and Packages in Emacs 25.1
 
 ** scss-mode (a minor variant of css-mode)
+
+** `tildify-mode' allows to automatically insert hard spaces as one
+types the text.  Breaking line after a single-character words is
+forbidden by Czech and Polish typography (and may be discouraged in
+other languages), so `auto-tildify-mode' makes it easier to create
+a typographically-correct documents.
 \f
 * Incompatible Lisp Changes in Emacs 25.1
 
diff --git a/lisp/textmodes/tildify.el b/lisp/textmodes/tildify.el
index d935ff7..f5275d9 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.7
+;; Version:    4.6
 ;; Keywords:   text, TeX, SGML, wp
 
 ;; This file is part of GNU Emacs.
@@ -401,6 +401,92 @@ replacements done and response is one of symbols: t (all right), nil
                         (t t))))))
 
 
+;;; *** Tildify Mode ***
+
+(defcustom tildify-space-pattern "[,:;(][ \t]*[a]\\|\\<[AIKOSUVWZikosuvwz]"
+  "Pattern specifying whether to insert a hard space at point.
+
+If the pattern matches `looking-back', a hard space needs to be inserted instead
+of a space at point.  The regexp is always case sensitive, regardless of the
+current `case-fold-search' setting."
+  :version "25.1"
+  :group 'tildify
+  :type 'string)
+
+(defcustom tildify-space-predicates '(tildify-space-region-predicate)
+  "A list of predicate functions for `tildify-space' function."
+  :version "25.1"
+  :group 'tildify
+  :type '(repeat 'function))
+
+
+;;;###autoload
+(defun tildify-space ()
+  "Convert space before point into a hard space if the context is right.
+
+If
+ * character before point is a space character,
+ * character before that has “w” character syntax (i.e. it's a word
+   constituent),
+ * `tildify-space-pattern' matches when `looking-back' (no more than 10
+   characters) from before the space character, and
+ * all predicates in `tildify-space-predicates' return non-nil,
+replace the space character with a hard space specified by
+`tildify-space-string' (note that the function does not take
+`tildify-string-alist' into consideration).
+
+Return t if conversion happened, nil otherwise.
+
+This function is meant to be used as a `post-self-insert-hook'."
+  (interactive)
+  (let ((p (point)) case-fold-search)
+    (when (and (> (- p (point-min)) 2)
+               (eq (preceding-char) ?\s)
+               (eq (char-syntax (char-before (1- p))) ?w)
+               (not (string-equal " " tildify-space-string))
+               (save-excursion
+                 (goto-char (1- p))
+                 (looking-back tildify-space-pattern
+                               (max (point-min) (- p 10))))
+               (run-hook-with-args-until-failure 'tildify-space-predicates))
+      (delete-char -1)
+      (insert tildify-space-string)
+      t)))
+
+(defun tildify-space-region-predicate ()
+  "Check whether character before point should be tildified.
+Based on `tildify-foreach-region-function', check whether character before,
+which is assumed to be a space character, should be replaced with a hard space."
+  (catch 'found
+    (tildify--foreach-region (lambda (_b _e) (throw 'found t)) (1- (point)) (point))))
+
+;;;###autoload
+(define-minor-mode tildify-mode
+  "Adds electric behaviour to space character.
+
+When space is inserted into a buffer in a position where hard space is required
+instead (determined by `tildify-space-pattern' and `tildify-space-predicates'),
+that space character is replaced by a hard space specified by
+`tildify-space-string'.  Converting of the space is done by `tildify-space'.
+
+When `tildify-mode' is enabled, if `tildify-string-alist' specifies a hard space
+representation for current major mode, the `tildify-space-string' buffer-local
+variable will be set to the representation."
+  nil " ~" nil
+  (when tildify-mode
+    (let ((space (tildify--pick-alist-entry tildify-string-alist)))
+      (if (not (string-equal " " (or space tildify-space-string)))
+          (when space
+            (setq tildify-space-string space))
+        (message (eval-when-compile
+                   (concat "Hard space is a single space character, tildify-"
+                           "mode won't have any effect, disabling.")))
+        (setq tildify-mode nil))))
+  (if tildify-mode
+      (add-hook 'post-self-insert-hook 'tildify-space nil t)
+    (remove-hook 'post-self-insert-hook 'tildify-space t)))
+
+
 ;;; *** Announce ***
 
 (provide 'tildify)
diff --git a/test/automated/tildify-tests.el b/test/automated/tildify-tests.el
index 55d2d57..fc68787 100644
--- a/test/automated/tildify-tests.el
+++ b/test/automated/tildify-tests.el
@@ -185,6 +185,44 @@ The function must terminate as soon as callback returns nil."
       (+ (point-min) 10) (+ (point-min) 20)))) ; start at "3" end past "5"
 
 
+(defun tildify-space-test--test (modes nbsp env-open &optional set-space-string)
+  (with-temp-buffer
+    (dolist (mode modes)
+      (funcall mode)
+      (when set-space-string
+        (setq-local tildify-space-string nbsp))
+      (let ((header (concat "Testing `tildify-space' in "
+                            (symbol-name mode) "\n")))
+        ;; Replace space with hard space.
+        (erase-buffer)
+        (insert header "Lorem v ")
+        (should (tildify-space))
+        (should (string-equal (concat header "Lorem v" nbsp) (buffer-string)))
+        ;; Inside and ignore environment, replacing does not happen.
+        (erase-buffer)
+        (insert header env-open "Lorem v ")
+        (should (not (tildify-space)))
+        (should (string-equal (concat header env-open "Lorem v ")
+                              (buffer-string)))))))
+
+(ert-deftest tildify-space-test-html ()
+  "Tests auto-tildification in an HTML document"
+  (tildify-space-test--test '(html-mode sgml-mode) " " "<pre>"))
+
+(ert-deftest tildify-space-test-html-nbsp ()
+  "Tests auto-tildification in an HTML document"
+  (tildify-space-test--test '(html-mode sgml-mode) "&nbsp;" "<pre>" t))
+
+(ert-deftest tildify-space-test-xml ()
+  "Tests auto-tildification in an XML document"
+  (tildify-space-test--test '(nxml-mode) " " "<! -- "))
+
+(ert-deftest tildify-space-test-tex ()
+  "Tests tildification in a TeX document"
+  (tildify-space-test--test '(tex-mode latex-mode plain-tex-mode)
+                            "~" "\\verb# "))
+
+
 (provide 'tildify-tests)
 
 ;;; tildify-tests.el ends here
-- 
2.1.0.rc2.206.gedb03e5






^ permalink raw reply related	[flat|nested] 30+ messages in thread

* bug#18730: [PATCH 2/2] tildify.el: Add `tildify-double-space-undos'.
  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   ` Michal Nazarewicz
  2014-12-10 17:44   ` bug#18730: [PATCH 1/2] tildify.el: Add `tildify-space' and `tildify-mode' Michal Nazarewicz
  1 sibling, 0 replies; 30+ messages in thread
From: Michal Nazarewicz @ 2014-11-24 14:20 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 18730

* lisp/textmodes/tildify.el (tildify-double-space-undos): A new
variable specifying whether pressing space in `tildify-mode' after
a space has been replaced with hard space undos the substitution.
(tildify-space): Add code branch for handling `tildify-doule-space'.

* tests/automated/tildify-tests.el (tildify-space-undo-test--test):
A new helper function for testing `tildify-double-space-undos'
behaviour in the `tildify-space' function.
(tildify-space-undo-test-html, tildify-space-undo-test-html-nbsp)
(tildify-space-undo-test-xml, tildify-space-undo-test-tex): New
tests for `tildify-doule-space-undos' behaviour.
---
 lisp/textmodes/tildify.el       | 53 +++++++++++++++++++++++++++--------------
 test/automated/tildify-tests.el | 33 +++++++++++++++++++++++++
 2 files changed, 68 insertions(+), 18 deletions(-)

diff --git a/lisp/textmodes/tildify.el b/lisp/textmodes/tildify.el
index f5275d9..3d82330 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.6
+;; Version:    4.6.1
 ;; Keywords:   text, TeX, SGML, wp
 
 ;; This file is part of GNU Emacs.
@@ -419,6 +419,11 @@ current `case-fold-search' setting."
   :group 'tildify
   :type '(repeat 'function))
 
+(defcustom tildify-double-space-undos t
+  "Weather `tildify-space' should undo hard space when space is typed again."
+  :version "25.1"
+  :group 'tildify
+  :type 'boolean)
 
 ;;;###autoload
 (defun tildify-space ()
@@ -431,27 +436,39 @@ If
  * `tildify-space-pattern' matches when `looking-back' (no more than 10
    characters) from before the space character, and
  * all predicates in `tildify-space-predicates' return non-nil,
-replace the space character with a hard space specified by
-`tildify-space-string' (note that the function does not take
-`tildify-string-alist' into consideration).
+replace the space character with value of `tildify-space-string' and
+return t.
 
-Return t if conversion happened, nil otherwise.
+Otherwise, if
+ * `tildify-double-space-undos' variable is non-nil,
+ * character before point is a space character, and
+ * text before that is a hard space as defined by
+   `tildify-space-string' variable,
+remove the hard space and leave only the space character.
 
 This function is meant to be used as a `post-self-insert-hook'."
   (interactive)
-  (let ((p (point)) case-fold-search)
-    (when (and (> (- p (point-min)) 2)
-               (eq (preceding-char) ?\s)
-               (eq (char-syntax (char-before (1- p))) ?w)
-               (not (string-equal " " tildify-space-string))
-               (save-excursion
-                 (goto-char (1- p))
-                 (looking-back tildify-space-pattern
-                               (max (point-min) (- p 10))))
-               (run-hook-with-args-until-failure 'tildify-space-predicates))
-      (delete-char -1)
-      (insert tildify-space-string)
-      t)))
+  (let* ((p (point)) (p-1 (1- p)) (n (- p (point-min)))
+         (l (length tildify-space-string)) (l+1 (1+ l))
+         case-fold-search)
+    (when (and (> n 2) (eq (preceding-char) ?\s))
+      (cond
+       ((and (eq (char-syntax (char-before p-1)) ?w)
+             (save-excursion
+               (goto-char p-1)
+               (looking-back tildify-space-pattern (max (point-min) (- p 10))))
+             (run-hook-with-args-until-failure 'tildify-space-predicates))
+        (delete-char -1)
+        (insert tildify-space-string)
+        t)
+       ((and tildify-double-space-undos
+             (> n l+1)
+             (string-equal tildify-space-string
+                           (buffer-substring (- p l+1) p-1)))
+        (goto-char p-1)
+        (delete-char (- l))
+        (goto-char (1+ (point)))
+        nil)))))
 
 (defun tildify-space-region-predicate ()
   "Check whether character before point should be tildified.
diff --git a/test/automated/tildify-tests.el b/test/automated/tildify-tests.el
index fc68787..8fd87ab 100644
--- a/test/automated/tildify-tests.el
+++ b/test/automated/tildify-tests.el
@@ -223,6 +223,39 @@ The function must terminate as soon as callback returns nil."
                             "~" "\\verb# "))
 
 
+(defun tildify-space-undo-test--test
+    (modes nbsp env-open &optional set-space-string)
+  (with-temp-buffer
+    (dolist (mode modes)
+      (funcall mode)
+      (when set-space-string
+        (setq-local tildify-space-string nbsp))
+      (let ((header (concat "Testing double-space-undos in "
+                            (symbol-name mode) "\n")))
+        (erase-buffer)
+        (insert header "Lorem v" nbsp " ")
+        (should (not (tildify-space)))
+        (should (string-equal (concat header "Lorem v ") (buffer-string)))))))
+
+(ert-deftest tildify-space-undo-test-html ()
+  "Tests auto-tildification in an HTML document"
+  (tildify-space-undo-test--test '(html-mode sgml-mode) " " "<pre>"))
+
+(ert-deftest tildify-space-undo-test-html-nbsp ()
+  "Tests auto-tildification in an HTML document"
+  (tildify-space-undo-test--test '(html-mode sgml-mode) "&nbsp;" "<pre>" t))
+
+(ert-deftest tildify-space-undo-test-xml ()
+  "Tests auto-tildification in an XML document"
+  (tildify-space-undo-test--test '(nxml-mode) " " "<! -- "))
+
+(ert-deftest tildify-space-undo-test-tex ()
+  "Tests tildification in a TeX document"
+  (tildify-space-undo-test--test '(tex-mode latex-mode plain-tex-mode)
+                                 "~" "\\verb# "))
+
+
+
 (provide 'tildify-tests)
 
 ;;; tildify-tests.el ends here
-- 
2.1.0.rc2.206.gedb03e5






^ permalink raw reply related	[flat|nested] 30+ messages in thread

* bug#18730: [PATCH 1/2] tildify.el: Add `tildify-space' and `tildify-mode'.
  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   ` Michal Nazarewicz
  1 sibling, 0 replies; 30+ messages in thread
From: Michal Nazarewicz @ 2014-12-10 17:44 UTC (permalink / raw)
  To: 18730

Ping.

-- 
Best regards,                                         _     _
.o. | Liege of Serenely Enlightened Majesty of      o' \,=./ `o
..o | Computer Science,  Michał “mina86” Nazarewicz    (o o)
ooo +--<mpn@google.com>--<xmpp:mina86@jabber.org>--ooO--(_)--Ooo--





^ permalink raw reply	[flat|nested] 30+ messages in thread

end of thread, other threads:[~2014-12-10 17:44 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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                             ` bug#18730: [PATCH 2/3] tildify.el: introduce a `tildify-pattern' variable Michal Nazarewicz
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

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).