From: Reuben Thomas <rrt@sc3d.org>
To: 24745@debbugs.gnu.org
Subject: bug#24745: Acknowledgement (25.1.50; whitespace.el: fix beginning/end of buffer checks)
Date: Fri, 21 Oct 2016 15:38:44 +0100 [thread overview]
Message-ID: <CAOnWdoihkftOW6amiR5b+=AN4_VAjOe8NQmOmU3Czfr1G_OzwQ@mail.gmail.com> (raw)
In-Reply-To: <handler.24745.B.14769667565022.ack@debbugs.gnu.org>
[-- Attachment #1.1: Type: text/plain, Size: 992 bytes --]
I have expanded my work on whitespace.el to address other problems.
First, I revised my previous patch, which had an error in the new version
of whitespace-empty-at-eob-regexp.
Next, I removed some duplicate documentation from the Commentary section:
it was already out of date in one or two places, and it duplicated
information readily available in docstrings.
Next, I fixed some problems with whitespace-space-after-tab-regexp.
Finally, I fixed whitespace-report-region to respect user settings: it no
longer returns true when the region has a problem not covered by
whitespace-style; however, it still diagnoses and reports all possible
problems.
There's one more problem with whitespace-report-region I would like to fix,
which is that currently the force parameter changes whitespace-style
globally; it should, I believe, only change it for the duration of the
function.
I'd appreciate some review of these patches (all against current git
master).
TIA!
--
http://rrt.sc3d.org
[-- Attachment #1.2: Type: text/html, Size: 2090 bytes --]
[-- Attachment #2: 0001-whitespace-fix-bob-eob-checks.patch --]
[-- Type: text/x-patch, Size: 1736 bytes --]
From 343ecf32200da2b1d8e93b7d3cc16da288ec851e Mon Sep 17 00:00:00 2001
From: Reuben Thomas <rrt@sc3d.org>
Date: Thu, 20 Oct 2016 13:17:58 +0100
Subject: [PATCH 1/4] whitespace: fix bob/eob checks
* whitespace.el: make `empty' checks work at beginning & end of buffer
in whitespace-report-region, and only there (i.e. they will never match
in regions that don't include the start or end of the buffer).
---
lisp/whitespace.el | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/lisp/whitespace.el b/lisp/whitespace.el
index 0f6b8df..6164585 100644
--- a/lisp/whitespace.el
+++ b/lisp/whitespace.el
@@ -828,7 +828,7 @@ whitespace-indentation-regexp
:group 'whitespace)
-(defcustom whitespace-empty-at-bob-regexp "^\\(\\([ \t]*\n\\)+\\)"
+(defcustom whitespace-empty-at-bob-regexp "\\`\\(\\([ \t]*\n\\)+\\)"
"Specify regexp for empty lines at beginning of buffer.
Used when `whitespace-style' includes `empty'."
@@ -836,7 +836,7 @@ whitespace-empty-at-bob-regexp
:group 'whitespace)
-(defcustom whitespace-empty-at-eob-regexp "^\\([ \t\n]+\\)"
+(defcustom whitespace-empty-at-eob-regexp "^\\([ \t\n]*\\(\n\\{2,\\}\\|[ \t]+\\)\\)\\'"
"Specify regexp for empty lines at end of buffer.
Used when `whitespace-style' includes `empty'."
@@ -1515,7 +1515,7 @@ whitespace-cleanup
(when (looking-at whitespace-empty-at-bob-regexp)
(delete-region (match-beginning 1) (match-end 1)))
(when (re-search-forward
- (concat whitespace-empty-at-eob-regexp "\\'") nil t)
+ whitespace-empty-at-eob-regexp nil t)
(delete-region (match-beginning 1) (match-end 1)))))))
;; PROBLEM 3: 8 or more SPACEs at bol
;; PROBLEM 4: SPACEs before TAB
--
2.7.4
[-- Attachment #3: 0002-whitespace.el-remove-duplicate-documentation.patch --]
[-- Type: text/x-patch, Size: 5036 bytes --]
From 23658bf1cf606408f1aea2385c2e64ae150a268a Mon Sep 17 00:00:00 2001
From: Reuben Thomas <rrt@sc3d.org>
Date: Fri, 21 Oct 2016 15:20:07 +0100
Subject: [PATCH 2/4] whitespace.el: remove duplicate documentation
* whitespace.el: remove duplicate documentation from the Commentary
section which duplicate and in some places contradict (due to being
out of date) the docstrings.
---
lisp/whitespace.el | 116 -----------------------------------------------------
1 file changed, 116 deletions(-)
diff --git a/lisp/whitespace.el b/lisp/whitespace.el
index 6164585..eeb1730 100644
--- a/lisp/whitespace.el
+++ b/lisp/whitespace.el
@@ -182,45 +182,6 @@
;; `whitespace-cleanup-region'
;; Cleanup some blank problems at region.
;;
-;; The problems, which are cleaned up, are:
-;;
-;; 1. empty lines at beginning of buffer.
-;; 2. empty lines at end of buffer.
-;; If `whitespace-style' includes the value `empty', remove all
-;; empty lines at beginning and/or end of buffer.
-;;
-;; 3. 8 or more SPACEs at beginning of line.
-;; If `whitespace-style' includes the value `indentation':
-;; replace 8 or more SPACEs at beginning of line by TABs, if
-;; `indent-tabs-mode' is non-nil; otherwise, replace TABs by
-;; SPACEs.
-;; If `whitespace-style' includes the value `indentation::tab',
-;; replace 8 or more SPACEs at beginning of line by TABs.
-;; If `whitespace-style' includes the value `indentation::space',
-;; replace TABs by SPACEs.
-;;
-;; 4. SPACEs before TAB.
-;; If `whitespace-style' includes the value `space-before-tab':
-;; replace SPACEs by TABs, if `indent-tabs-mode' is non-nil;
-;; otherwise, replace TABs by SPACEs.
-;; If `whitespace-style' includes the value
-;; `space-before-tab::tab', replace SPACEs by TABs.
-;; If `whitespace-style' includes the value
-;; `space-before-tab::space', replace TABs by SPACEs.
-;;
-;; 5. SPACEs or TABs at end of line.
-;; If `whitespace-style' includes the value `trailing', remove all
-;; SPACEs or TABs at end of line.
-;;
-;; 6. 8 or more SPACEs after TAB.
-;; If `whitespace-style' includes the value `space-after-tab':
-;; replace SPACEs by TABs, if `indent-tabs-mode' is non-nil;
-;; otherwise, replace TABs by SPACEs.
-;; If `whitespace-style' includes the value `space-after-tab::tab',
-;; replace SPACEs by TABs.
-;; If `whitespace-style' includes the value
-;; `space-after-tab::space', replace TABs by SPACEs.
-;;
;;
;; Hooks
;; -----
@@ -237,83 +198,6 @@
;; It is evaluated after whitespace package is loaded.
;;
;;
-;; Options
-;; -------
-;;
-;; Below it's shown a brief description of whitespace options, please,
-;; see the options declaration in the code for a long documentation.
-;;
-;; `whitespace-style' Specify which kind of blank is
-;; visualized.
-;;
-;; `whitespace-space' Face used to visualize SPACE.
-;;
-;; `whitespace-hspace' Face used to visualize HARD SPACE.
-;;
-;; `whitespace-tab' Face used to visualize TAB.
-;;
-;; `whitespace-newline' Face used to visualize NEWLINE char
-;; mapping.
-;;
-;; `whitespace-trailing' Face used to visualize trailing
-;; blanks.
-;;
-;; `whitespace-line' Face used to visualize "long" lines.
-;;
-;; `whitespace-space-before-tab' Face used to visualize SPACEs
-;; before TAB.
-;;
-;; `whitespace-indentation' Face used to visualize 8 or more
-;; SPACEs at beginning of line.
-;;
-;; `whitespace-big-indent' Face used to visualize big indentation.
-;;
-;; `whitespace-empty' Face used to visualize empty lines at
-;; beginning and/or end of buffer.
-;;
-;; `whitespace-space-after-tab' Face used to visualize 8 or more
-;; SPACEs after TAB.
-;;
-;; `whitespace-space-regexp' Specify SPACE characters regexp.
-;;
-;; `whitespace-hspace-regexp' Specify HARD SPACE characters regexp.
-;;
-;; `whitespace-tab-regexp' Specify TAB characters regexp.
-;;
-;; `whitespace-trailing-regexp' Specify trailing characters regexp.
-;;
-;; `whitespace-space-before-tab-regexp' Specify SPACEs before TAB
-;; regexp.
-;;
-;; `whitespace-indentation-regexp' Specify regexp for 8 or more
-;; SPACEs at beginning of line.
-;;
-;; `whitespace-big-indent-regexp' Specify big indentation at beginning of line
-;; regexp.
-;;
-;; `whitespace-empty-at-bob-regexp' Specify regexp for empty lines
-;; at beginning of buffer.
-;;
-;; `whitespace-empty-at-eob-regexp' Specify regexp for empty lines
-;; at end of buffer.
-;;
-;; `whitespace-space-after-tab-regexp' Specify regexp for 8 or more
-;; SPACEs after TAB.
-;;
-;; `whitespace-line-column' Specify column beyond which the line
-;; is highlighted.
-;;
-;; `whitespace-display-mappings' Specify an alist of mappings
-;; for displaying characters.
-;;
-;; `whitespace-global-modes' Modes for which global
-;; `whitespace-mode' is automagically
-;; turned on.
-;;
-;; `whitespace-action' Specify which action is taken when a
-;; buffer is visited or written.
-;;
-;;
;; Acknowledgments
;; ---------------
;;
--
2.7.4
[-- Attachment #4: 0003-whitespace.el-fix-whitespace-space-after-tab-regexp.patch --]
[-- Type: text/x-patch, Size: 1655 bytes --]
From 41f057a224fec3d672f936b09031e7d595d69cef Mon Sep 17 00:00:00 2001
From: Reuben Thomas <rrt@sc3d.org>
Date: Fri, 21 Oct 2016 15:23:08 +0100
Subject: [PATCH 3/4] whitespace.el: fix whitespace-space-after-tab-regexp
* whitespace.el: match all the spaces after tabs for highlighting, not
just the first tab-width. Fix whitespace-space-after-tab::space
version so that it requires at least tab-width spaces, not just 1.
---
lisp/whitespace.el | 20 +++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)
diff --git a/lisp/whitespace.el b/lisp/whitespace.el
index eeb1730..b798e7e 100644
--- a/lisp/whitespace.el
+++ b/lisp/whitespace.el
@@ -729,8 +729,8 @@ whitespace-empty-at-eob-regexp
(defcustom whitespace-space-after-tab-regexp
- '("\t+\\(\\( \\{%d\\}\\)+\\)"
- . "\\(\t+\\) +")
+ '("\t+\\(\\( \\{%d,\\}\\)+\\)"
+ . "\\(\t+\\) \\{%d,\\}")
"Specify regexp for 8 or more SPACEs after TAB.
It is a cons where the cons car is used for SPACEs visualization
@@ -1558,13 +1558,15 @@ whitespace-replace-action
(defun whitespace-regexp (regexp &optional kind)
"Return REGEXP depending on `whitespace-indent-tabs-mode'."
- (cond
- ((or (eq kind 'tab)
- whitespace-indent-tabs-mode)
- (format (car regexp) whitespace-tab-width))
- ((or (eq kind 'space)
- (not whitespace-indent-tabs-mode))
- (cdr regexp))))
+ (format
+ (cond
+ ((or (eq kind 'tab)
+ whitespace-indent-tabs-mode)
+ (car regexp))
+ ((or (eq kind 'space)
+ (not whitespace-indent-tabs-mode))
+ (cdr regexp)))
+ whitespace-tab-width))
(defun whitespace-indentation-regexp (&optional kind)
--
2.7.4
[-- Attachment #5: 0004-whitespace.el-make-whitespace-report-region-respect-.patch --]
[-- Type: text/x-patch, Size: 1284 bytes --]
From 2a996815dc9bb8922eb9c31014e6526ed6daacb7 Mon Sep 17 00:00:00 2001
From: Reuben Thomas <rrt@sc3d.org>
Date: Fri, 21 Oct 2016 15:25:12 +0100
Subject: [PATCH 4/4] whitespace.el: make whitespace-report-region respect
current settings
* whitespace.el: make whitespace-report-region respect whitespace-style,
including any additions made by the force parameter. This means that
the function does not return t unless a whitespace problem that the
user cares about is reported.
---
lisp/whitespace.el | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/lisp/whitespace.el b/lisp/whitespace.el
index b798e7e..5300faf 100644
--- a/lisp/whitespace.el
+++ b/lisp/whitespace.el
@@ -1732,8 +1732,10 @@ whitespace-report-region
(whitespace-space-after-tab-regexp 'space))
(t
(cdr option)))))
- (and (re-search-forward regexp rend t)
- (setq has-bogus t))))
+ (when (re-search-forward regexp rend t)
+ (unless has-bogus
+ (setq has-bogus (memq (car option) whitespace-style)))
+ t)))
whitespace-report-list)))
(when (pcase report-if-bogus (`nil t) (`never nil) (_ has-bogus))
(whitespace-kill-buffer whitespace-report-buffer-name)
--
2.7.4
prev parent reply other threads:[~2016-10-21 14:38 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-20 12:32 bug#24745: 25.1.50; whitespace.el: fix beginning/end of buffer checks Reuben Thomas
2016-10-20 22:43 ` Dmitry Gutov
2016-10-21 14:42 ` Reuben Thomas
2016-10-21 14:45 ` Dmitry Gutov
2016-10-21 14:52 ` Reuben Thomas
2016-10-24 23:36 ` Dmitry Gutov
2016-10-25 18:44 ` Reuben Thomas
2016-10-25 22:45 ` Dmitry Gutov
2016-10-25 23:26 ` Reuben Thomas
2016-11-01 15:32 ` Reuben Thomas
2016-11-03 1:07 ` Dmitry Gutov
2016-11-03 12:39 ` Reuben Thomas
2016-11-03 1:06 ` Dmitry Gutov
2016-11-03 12:38 ` Reuben Thomas
[not found] ` <handler.24745.B.14769667565022.ack@debbugs.gnu.org>
2016-10-21 14:38 ` Reuben Thomas [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAOnWdoihkftOW6amiR5b+=AN4_VAjOe8NQmOmU3Czfr1G_OzwQ@mail.gmail.com' \
--to=rrt@sc3d.org \
--cc=24745@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this 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.