* bug#10772: 24.0.93; [patch] Convert tcl-auto-fill-mode to use define-minor-mode
@ 2012-02-09 6:49 William Stevenson
2012-02-09 15:18 ` Juanma Barranquero
2012-02-09 22:09 ` Stefan Monnier
0 siblings, 2 replies; 16+ messages in thread
From: William Stevenson @ 2012-02-09 6:49 UTC (permalink / raw)
To: 10772
In the documentation of auto-fill-mode it says:
"When `auto-fill-mode' is on, the `auto-fill-function' variable is
non-`nil'."
Which makes the `if' redundant in this case, the THEN & ELSE bodies can
be placed below the call to turn auto-fill-mode on/off.
Also updated the documentation to reflect the auto generated
`tcl-auto-fill-mode-hook'.
=== modified file 'lisp/progmodes/tcl.el'
--- lisp/progmodes/tcl.el 2012-01-19 07:21:25 +0000
+++ lisp/progmodes/tcl.el 2012-02-09 06:18:32 +0000
@@ -1408,13 +1408,18 @@
tcl-application file tcl-command-switches)
(if and-go (switch-to-tcl t)))))))
-(defun tcl-auto-fill-mode (&optional arg)
- "Like `auto-fill-mode', but sets `comment-auto-fill-only-comments'."
- (interactive "P")
- (auto-fill-mode arg)
- (if auto-fill-function
- (set (make-local-variable 'comment-auto-fill-only-comments) t)
- (kill-local-variable 'comment-auto-fill-only-comments)))
+(define-minor-mode tcl-auto-fill-mode
+ "Like `auto-fill-mode', but sets `comment-auto-fill-only-comments'.
+Turning the mode on or off runs `tcl-auto-fill-mode-hook'."
+ :init-value nil
+ (cond ((null tcl-auto-fill-mode)
+ ;; Turn mode off
+ (auto-fill-mode 0)
+ (kill-local-variable 'comment-auto-fill-only-comments))
+ (t
+ ;; Turn mode on
+ (auto-fill-mode)
+ (set (make-local-variable 'comment-auto-fill-only-comments) t))))
(defun tcl-electric-hash (&optional count)
"Insert a `#' and quote if it does not start a real comment.
^ permalink raw reply [flat|nested] 16+ messages in thread
* bug#10772: 24.0.93; [patch] Convert tcl-auto-fill-mode to use define-minor-mode
2012-02-09 6:49 bug#10772: 24.0.93; [patch] Convert tcl-auto-fill-mode to use define-minor-mode William Stevenson
@ 2012-02-09 15:18 ` Juanma Barranquero
2012-02-09 22:09 ` Stefan Monnier
1 sibling, 0 replies; 16+ messages in thread
From: Juanma Barranquero @ 2012-02-09 15:18 UTC (permalink / raw)
To: William Stevenson; +Cc: 10772
On Thu, Feb 9, 2012 at 07:49, William Stevenson <yhvh2000@gmail.com> wrote:
> + (auto-fill-mode)
That is correct, but I think it is customary (and clearer IMHO) to
pass an explicit argument, like (auto-fill-mode 1)
Juanma
^ permalink raw reply [flat|nested] 16+ messages in thread
* bug#10772: 24.0.93; [patch] Convert tcl-auto-fill-mode to use define-minor-mode
2012-02-09 6:49 bug#10772: 24.0.93; [patch] Convert tcl-auto-fill-mode to use define-minor-mode William Stevenson
2012-02-09 15:18 ` Juanma Barranquero
@ 2012-02-09 22:09 ` Stefan Monnier
2012-02-11 15:27 ` William Stevenson
1 sibling, 1 reply; 16+ messages in thread
From: Stefan Monnier @ 2012-02-09 22:09 UTC (permalink / raw)
To: William Stevenson; +Cc: 10772
> -(defun tcl-auto-fill-mode (&optional arg)
> - "Like `auto-fill-mode', but sets `comment-auto-fill-only-comments'."
> - (interactive "P")
> - (auto-fill-mode arg)
> - (if auto-fill-function
> - (set (make-local-variable 'comment-auto-fill-only-comments) t)
> - (kill-local-variable 'comment-auto-fill-only-comments)))
> +(define-minor-mode tcl-auto-fill-mode
> + "Like `auto-fill-mode', but sets `comment-auto-fill-only-comments'.
> +Turning the mode on or off runs `tcl-auto-fill-mode-hook'."
> + :init-value nil
> + (cond ((null tcl-auto-fill-mode)
> + ;; Turn mode off
> + (auto-fill-mode 0)
> + (kill-local-variable 'comment-auto-fill-only-comments))
> + (t
> + ;; Turn mode on
> + (auto-fill-mode)
> + (set (make-local-variable 'comment-auto-fill-only-comments) t))))
The problem with this approach is that it creates new possible states,
e.g. if the user enables tcl-auto-fill-mode and then disables
auto-fill-mode.
Maybe we could use an approach like the one I used for
(binary-)overwrite-mode.
Stefan
^ permalink raw reply [flat|nested] 16+ messages in thread
* bug#10772: 24.0.93; [patch] Convert tcl-auto-fill-mode to use define-minor-mode
2012-02-09 22:09 ` Stefan Monnier
@ 2012-02-11 15:27 ` William Stevenson
2012-02-12 5:12 ` Stefan Monnier
0 siblings, 1 reply; 16+ messages in thread
From: William Stevenson @ 2012-02-11 15:27 UTC (permalink / raw)
To: 10772
Stefan Monnier <monnier@IRO.UMontreal.CA> writes:
> The problem with this approach is that it creates new possible states,
> e.g. if the user enables tcl-auto-fill-mode and then disables
> auto-fill-mode.
The correct behavior seems to be if the tcl-auto-fill-mode is enabled
then calling auto-fill-mode will turn *auto-fill-mode off.
> Maybe we could use an approach like the one I used for
> (binary-)overwrite-mode.
I've been looking at this for the past day or so, and I'm still not sure
I know exactly what to do, but I've come up with 2 options.
This option works as I expect, ie when tcl-auto-fill-mode is enabled,
calling auto-fill-mode disables tcl-auto-fill-mode and auto-fill-mode.
--8<---------------cut here---------------start------------->8---
;; Docstrings elided
(define-minor-mode tcl-auto-fill-mode
:variable (eq auto-fill-function normal-auto-fill-function)
(if auto-fill-function
(kill-local-variable 'comment-auto-fill-only-comments)
(set (make-local-variable 'comment-auto-fill-only-comments) t)))
--8<---------------cut here---------------end--------------->8---
Or something more like this, which seems more in the spirit of binary
overwrite mode.
--8<---------------cut here---------------start------------->8---
;; Docstrings elided
(defun tcl-do-auto-fill ()
(if auto-fill-function
(kill-local-variable 'comment-auto-fill-only-comments)
(set (make-local-variable 'comment-auto-fill-only-comments) t))
(do-auto-fill))
(defvar tcl-auto-fill-function 'tcl-do-auto-fill)
(define-minor-mode tcl-auto-fill-mode
:variable (eq auto-fill-function tcl-auto-fill-function))
--8<---------------cut here---------------end--------------->8---
However other progmodes define f90-do-auto-fill, c-do-auto-fill,
cperl-do-auto-fill but tend to do the following.
--8<---------------cut here---------------start------------->8---
(set (make-local-variable 'normal-auto-fill-function) 'foo-do-auto-fill)
--8<---------------cut here---------------end--------------->8---
These 3 modes (and some others from cursory checking) don't define
foo-auto-fill-mode and just let the user call auto-fill-mode - which
makes me wonder if defining tcl-auto-fill-mode is the right thing to do
anyway.
William
^ permalink raw reply [flat|nested] 16+ messages in thread
* bug#10772: 24.0.93; [patch] Convert tcl-auto-fill-mode to use define-minor-mode
2012-02-11 15:27 ` William Stevenson
@ 2012-02-12 5:12 ` Stefan Monnier
2014-02-25 13:30 ` Xue Fuqiao
0 siblings, 1 reply; 16+ messages in thread
From: Stefan Monnier @ 2012-02-12 5:12 UTC (permalink / raw)
To: William Stevenson; +Cc: 10772
> --8<---------------cut here---------------start------------->8---
> (set (make-local-variable 'normal-auto-fill-function) 'foo-do-auto-fill)
> --8<---------------cut here---------------end--------------->8---
> These 3 modes (and some others from cursory checking) don't define
> foo-auto-fill-mode and just let the user call auto-fill-mode - which
> makes me wonder if defining tcl-auto-fill-mode is the right thing to do
> anyway.
Actually, thinking about it some more, maybe tcl-auto-fill-mode should
be renamed (it has nothing specific to Tcl) and I think it could be
implemented along the lines of (100% untested):
(define-minor-mode auto-fill-noncode-mode
:variable
((and auto-fill-function comment-auto-fill-only-comments)
. (lambda (x)
(auto-fill-mode (if x 1 -1))
(if auto-fill-function
(set (make-local-variable 'comment-auto-fill-only-comments) t)
(kill-local-variable 'comment-auto-fill-only-comments)))))
-- Stefan
^ permalink raw reply [flat|nested] 16+ messages in thread
* bug#10772: 24.0.93; [patch] Convert tcl-auto-fill-mode to use define-minor-mode
2012-02-12 5:12 ` Stefan Monnier
@ 2014-02-25 13:30 ` Xue Fuqiao
2014-02-25 14:30 ` Stefan Monnier
0 siblings, 1 reply; 16+ messages in thread
From: Xue Fuqiao @ 2014-02-25 13:30 UTC (permalink / raw)
To: Stefan Monnier; +Cc: William Stevenson, 10772
What about the following patch:
=== modified file 'lisp/progmodes/tcl.el'
--- lisp/progmodes/tcl.el 2014-02-10 01:34:22 +0000
+++ lisp/progmodes/tcl.el 2014-02-25 13:22:36 +0000
@@ -1410,13 +1410,8 @@
tcl-application file tcl-command-switches)
(if and-go (switch-to-tcl t)))))))
-(defun tcl-auto-fill-mode (&optional arg)
- "Like `auto-fill-mode', but sets `comment-auto-fill-only-comments'."
- (interactive "P")
- (auto-fill-mode arg)
- (if auto-fill-function
- (set (make-local-variable 'comment-auto-fill-only-comments) t)
- (kill-local-variable 'comment-auto-fill-only-comments)))
+(define-obsolete-function-alias tcl-auto-fill-mode
+ auto-fill-noncode-mode "24.4")
(defun tcl-electric-hash (&optional count)
"Insert a `#' and quote if it does not start a real comment.
=== modified file 'lisp/simple.el'
--- lisp/simple.el 2014-02-21 13:22:14 +0000
+++ lisp/simple.el 2014-02-25 13:26:54 +0000
@@ -6146,6 +6146,16 @@
. (lambda (v) (setq auto-fill-function
(if v normal-auto-fill-function)))))
+(define-minor-mode auto-fill-noncode-mode
+ "Like `auto-fill-mode', but sets `comment-auto-fill-only-comments'."
+ :variable
+ ((and auto-fill-function comment-auto-fill-only-comments)
+ . (lambda (x)
+ (auto-fill-mode (if x 1 -1))
+ (if auto-fill-function
+ (setq-local comment-auto-fill-only-comments t)
+ (kill-local-variable 'comment-auto-fill-only-comments)))))
+
;; This holds a document string used to document auto-fill-mode.
(defun auto-fill-function ()
"Automatically break line at a previous space, in insertion of text."
^ permalink raw reply [flat|nested] 16+ messages in thread
* bug#10772: 24.0.93; [patch] Convert tcl-auto-fill-mode to use define-minor-mode
2014-02-25 13:30 ` Xue Fuqiao
@ 2014-02-25 14:30 ` Stefan Monnier
2014-02-25 22:25 ` Xue Fuqiao
0 siblings, 1 reply; 16+ messages in thread
From: Stefan Monnier @ 2014-02-25 14:30 UTC (permalink / raw)
To: Xue Fuqiao; +Cc: William Stevenson, 10772
> What about the following patch:
Tcl is not special wrt to filling and comments, AFAIK, so tcl-mode
should simply use the default auto-fill functionality without any
local tweaks.
Stefan
^ permalink raw reply [flat|nested] 16+ messages in thread
* bug#10772: 24.0.93; [patch] Convert tcl-auto-fill-mode to use define-minor-mode
2014-02-25 14:30 ` Stefan Monnier
@ 2014-02-25 22:25 ` Xue Fuqiao
2014-02-26 15:40 ` Stefan Monnier
0 siblings, 1 reply; 16+ messages in thread
From: Xue Fuqiao @ 2014-02-25 22:25 UTC (permalink / raw)
To: Stefan Monnier; +Cc: William Stevenson, 10772
Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> What about the following patch:
>
> Tcl is not special wrt to filling and comments, AFAIK, so tcl-mode
> should simply use the default auto-fill functionality without any
> local tweaks.
Right, and that's exactly what my patch does.
--
http://www.gnu.org/software/emacs/
^ permalink raw reply [flat|nested] 16+ messages in thread
* bug#10772: 24.0.93; [patch] Convert tcl-auto-fill-mode to use define-minor-mode
2014-02-25 22:25 ` Xue Fuqiao
@ 2014-02-26 15:40 ` Stefan Monnier
2014-02-26 22:40 ` Xue Fuqiao
0 siblings, 1 reply; 16+ messages in thread
From: Stefan Monnier @ 2014-02-26 15:40 UTC (permalink / raw)
To: Xue Fuqiao; +Cc: William Stevenson, 10772
>>> What about the following patch:
>> Tcl is not special wrt to filling and comments, AFAIK, so tcl-mode
>> should simply use the default auto-fill functionality without any
>> local tweaks.
> Right, and that's exactly what my patch does.
No, it preserves the "special behavior", just changing the
implementation to rely on the generic auto-fill code. My point is that
the special behavior is just a preference of the mode's author and hence
doesn't belong in the major mode's definition.
Stefan
^ permalink raw reply [flat|nested] 16+ messages in thread
* bug#10772: 24.0.93; [patch] Convert tcl-auto-fill-mode to use define-minor-mode
2014-02-26 15:40 ` Stefan Monnier
@ 2014-02-26 22:40 ` Xue Fuqiao
2014-02-27 2:55 ` Stefan Monnier
` (2 more replies)
0 siblings, 3 replies; 16+ messages in thread
From: Xue Fuqiao @ 2014-02-26 22:40 UTC (permalink / raw)
To: Stefan Monnier; +Cc: Xue Fuqiao, William Stevenson, 10772
Stefan Monnier <monnier@iro.umontreal.ca> writes:
>>> Tcl is not special wrt to filling and comments, AFAIK, so tcl-mode
>>> should simply use the default auto-fill functionality without any
>>> local tweaks.
>> Right, and that's exactly what my patch does.
>
> No, it preserves the "special behavior", just changing the
> implementation to rely on the generic auto-fill code. My point is that
> the special behavior is just a preference of the mode's author and hence
> doesn't belong in the major mode's definition.
Ah, I see. So here's the new patch (without ChangeLog/NEWS):
=== modified file 'lisp/progmodes/tcl.el'
--- lisp/progmodes/tcl.el 2014-02-10 01:34:22 +0000
+++ lisp/progmodes/tcl.el 2014-02-26 22:39:06 +0000
@@ -1410,13 +1410,8 @@
tcl-application file tcl-command-switches)
(if and-go (switch-to-tcl t)))))))
-(defun tcl-auto-fill-mode (&optional arg)
- "Like `auto-fill-mode', but sets `comment-auto-fill-only-comments'."
- (interactive "P")
- (auto-fill-mode arg)
- (if auto-fill-function
- (set (make-local-variable 'comment-auto-fill-only-comments) t)
- (kill-local-variable 'comment-auto-fill-only-comments)))
+(define-obsolete-function-alias tcl-auto-fill-mode
+ auto-fill-mode "24.4")
(defun tcl-electric-hash (&optional count)
"Insert a `#' and quote if it does not start a real comment.
--
http://www.gnu.org/software/emacs/
^ permalink raw reply [flat|nested] 16+ messages in thread
* bug#10772: 24.0.93; [patch] Convert tcl-auto-fill-mode to use define-minor-mode
2014-02-26 22:40 ` Xue Fuqiao
@ 2014-02-27 2:55 ` Stefan Monnier
2014-02-27 17:00 ` Glenn Morris
2017-06-03 3:45 ` npostavs
2 siblings, 0 replies; 16+ messages in thread
From: Stefan Monnier @ 2014-02-27 2:55 UTC (permalink / raw)
To: Xue Fuqiao; +Cc: William Stevenson, 10772
> Ah, I see. So here's the new patch (without ChangeLog/NEWS):
Looks better. Please also get rid of existing uses of
tcl-auto-fill-mode. And of course, wait for the trunk to re-open before
installing it.
Stefan
^ permalink raw reply [flat|nested] 16+ messages in thread
* bug#10772: 24.0.93; [patch] Convert tcl-auto-fill-mode to use define-minor-mode
2014-02-26 22:40 ` Xue Fuqiao
2014-02-27 2:55 ` Stefan Monnier
@ 2014-02-27 17:00 ` Glenn Morris
2014-02-27 22:33 ` Xue Fuqiao
2017-06-03 3:45 ` npostavs
2 siblings, 1 reply; 16+ messages in thread
From: Glenn Morris @ 2014-02-27 17:00 UTC (permalink / raw)
To: Xue Fuqiao; +Cc: 10772, William Stevenson
Xue Fuqiao wrote:
> +(define-obsolete-function-alias tcl-auto-fill-mode
> + auto-fill-mode "24.4")
Surely that is missing some quotes and can't work?
^ permalink raw reply [flat|nested] 16+ messages in thread
* bug#10772: 24.0.93; [patch] Convert tcl-auto-fill-mode to use define-minor-mode
2014-02-27 17:00 ` Glenn Morris
@ 2014-02-27 22:33 ` Xue Fuqiao
2016-02-24 6:42 ` Lars Ingebrigtsen
0 siblings, 1 reply; 16+ messages in thread
From: Xue Fuqiao @ 2014-02-27 22:33 UTC (permalink / raw)
To: Glenn Morris; +Cc: Xue Fuqiao, 10772, William Stevenson
Glenn Morris <rgm@gnu.org> writes:
> Xue Fuqiao wrote:
>
>> +(define-obsolete-function-alias tcl-auto-fill-mode
>> + auto-fill-mode "24.4")
>
> Surely that is missing some quotes and can't work?
Sorry for that. I'll add them when installing.
--
http://www.gnu.org/software/emacs/
^ permalink raw reply [flat|nested] 16+ messages in thread
* bug#10772: 24.0.93; [patch] Convert tcl-auto-fill-mode to use define-minor-mode
2014-02-27 22:33 ` Xue Fuqiao
@ 2016-02-24 6:42 ` Lars Ingebrigtsen
0 siblings, 0 replies; 16+ messages in thread
From: Lars Ingebrigtsen @ 2016-02-24 6:42 UTC (permalink / raw)
To: Xue Fuqiao; +Cc: 10772, William Stevenson, Stefan Monnier
Xue Fuqiao <xfq@gnu.org> writes:
> Glenn Morris <rgm@gnu.org> writes:
>
>> Xue Fuqiao wrote:
>>
>>> +(define-obsolete-function-alias tcl-auto-fill-mode
>>> + auto-fill-mode "24.4")
>>
>> Surely that is missing some quotes and can't work?
>
> Sorry for that. I'll add them when installing.
Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> Ah, I see. So here's the new patch (without ChangeLog/NEWS):
>
> Looks better. Please also get rid of existing uses of
> tcl-auto-fill-mode. And of course, wait for the trunk to re-open before
> installing it.
The trunk has been open for a few years now, but this doesn't seem to
have been applied. Xue?
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 16+ messages in thread
* bug#10772: 24.0.93; [patch] Convert tcl-auto-fill-mode to use define-minor-mode
2014-02-26 22:40 ` Xue Fuqiao
2014-02-27 2:55 ` Stefan Monnier
2014-02-27 17:00 ` Glenn Morris
@ 2017-06-03 3:45 ` npostavs
2017-06-28 0:38 ` npostavs
2 siblings, 1 reply; 16+ messages in thread
From: npostavs @ 2017-06-03 3:45 UTC (permalink / raw)
To: Xue Fuqiao; +Cc: William Stevenson, 10772, Stefan Monnier
[-- Attachment #1: Type: text/plain, Size: 246 bytes --]
Xue Fuqiao <xfq@gnu.org> writes:
> +(define-obsolete-function-alias tcl-auto-fill-mode
> + auto-fill-mode "24.4")
I think making this an alias breaks backwards compatibility needlessly.
I propose just marking it obsolete without changing it:
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch --]
[-- Type: text/x-diff, Size: 1814 bytes --]
From dd1ba59961cc216422349716fcfc62e656076500 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs@gmail.com>
Date: Sat, 1 Apr 2017 21:02:50 -0400
Subject: [PATCH v1] Make tcl-auto-fill-mode obsolete (Bug#10772)
* lisp/progmodes/tcl.el (tcl-auto-fill-mode): Declare obsolete.
* etc/NEWS: Announce it.
---
etc/NEWS | 5 +++++
lisp/progmodes/tcl.el | 5 +++--
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/etc/NEWS b/etc/NEWS
index 7972511f7a..cbd388b216 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1306,6 +1306,11 @@ window changed size when 'window-size-change-functions' are run.
*** The semantics of 'mouse-autoselect-window' has changed slightly.
For details see the section "Mouse Window Auto-selection" in the Elisp
manual.
+
+---
+** 'tcl-auto-fill-mode' is now declared obsolete. It's functionality
+can be replicated simply by setting 'comment-auto-fill-only-comments'.
+
\f
* Changes in Emacs 26.1 on Non-Free Operating Systems
diff --git a/lisp/progmodes/tcl.el b/lisp/progmodes/tcl.el
index 902a5aace0..de0cd50911 100644
--- a/lisp/progmodes/tcl.el
+++ b/lisp/progmodes/tcl.el
@@ -353,8 +353,6 @@ (defvar tcl-mode-hook nil
Quotes all \"#\" characters that don't correspond to actual
Tcl comments. (Useful when editing code not originally created
with this mode).
- `tcl-auto-fill-mode'
- Auto-filling of Tcl comments.
Add functions to the hook with `add-hook':
@@ -1413,6 +1411,9 @@ (defun tcl-restart-with-file (file &optional and-go)
(defun tcl-auto-fill-mode (&optional arg)
"Like `auto-fill-mode', but sets `comment-auto-fill-only-comments'."
+ (declare
+ (obsolete
+ "Use `auto-fill-mode' with `comment-auto-fill-only-comments'." "26.1"))
(interactive "P")
(auto-fill-mode arg)
(if auto-fill-function
--
2.11.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
end of thread, other threads:[~2017-06-28 0:38 UTC | newest]
Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-09 6:49 bug#10772: 24.0.93; [patch] Convert tcl-auto-fill-mode to use define-minor-mode William Stevenson
2012-02-09 15:18 ` Juanma Barranquero
2012-02-09 22:09 ` Stefan Monnier
2012-02-11 15:27 ` William Stevenson
2012-02-12 5:12 ` Stefan Monnier
2014-02-25 13:30 ` Xue Fuqiao
2014-02-25 14:30 ` Stefan Monnier
2014-02-25 22:25 ` Xue Fuqiao
2014-02-26 15:40 ` Stefan Monnier
2014-02-26 22:40 ` Xue Fuqiao
2014-02-27 2:55 ` Stefan Monnier
2014-02-27 17:00 ` Glenn Morris
2014-02-27 22:33 ` Xue Fuqiao
2016-02-24 6:42 ` Lars Ingebrigtsen
2017-06-03 3:45 ` npostavs
2017-06-28 0:38 ` npostavs
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.