unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#37418: [PATCH] Add new function to clear tags in tabulated list
@ 2019-09-16  1:54 Stefan Kangas
  2019-09-20 17:54 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 3+ messages in thread
From: Stefan Kangas @ 2019-09-16  1:54 UTC (permalink / raw)
  To: 37418

[-- Attachment #1: Type: text/plain, Size: 201 bytes --]

I found myself wanting to clear all tags in *Packages* buffer, but it
made more sense to implement this as general functionality in
tabulated list mode.  How does it look?

Best regards,
Stefan Kangas

[-- Attachment #2: 0001-Add-new-function-to-clear-tags-in-tabulated-list.patch --]
[-- Type: text/x-patch, Size: 2699 bytes --]

From 2cdd76d8d98835fa42ebd8b503bfc416563b1bd1 Mon Sep 17 00:00:00 2001
From: Stefan Kangas <stefankangas@gmail.com>
Date: Mon, 16 Sep 2019 03:48:47 +0200
Subject: [PATCH] Add new function to clear tags in tabulated list

* lisp/emacs-lisp/tabulated-list.el (tabulated-list-clear-all-tags):
New function to clear all tags from padding area in current buffer.
* doc/lispref/modes.texi (Tabulated List Mode): Document it.
* etc/NEWS: Announce it.
---
 doc/lispref/modes.texi            |  5 +++++
 etc/NEWS                          |  5 +++++
 lisp/emacs-lisp/tabulated-list.el | 13 +++++++++++++
 3 files changed, 23 insertions(+)

diff --git a/doc/lispref/modes.texi b/doc/lispref/modes.texi
index 7185c243e2..2e0c9e4655 100644
--- a/doc/lispref/modes.texi
+++ b/doc/lispref/modes.texi
@@ -1201,6 +1201,11 @@ Tabulated List Mode
 function advances point by one line.
 @end defun
 
+@defun tabulated-list-clear-all-tags
+This function clears all tags from the padding area in the current
+buffer.
+@end defun
+
 @defun tabulated-list-set-col col desc &optional change-entry-data
 This function changes the tabulated list entry at point, setting
 @var{col} to @var{desc}.  @var{col} is the column number to change, or
diff --git a/etc/NEWS b/etc/NEWS
index 252c6bf9b9..2204d34b00 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1707,6 +1707,11 @@ near the current column in Tabulated Lists (see variables
 list mode: 'w' (which widens the current column) and 'c' which makes
 the current column contract.
 
++++
+*** New function 'tabulated-list-clear-all-tags'.
+This function clears all tags from the padding area in the current
+buffer.  Tags are typically added by calling 'tabulated-list-put-tag'.
+
 ** Text mode
 
 +++
diff --git a/lisp/emacs-lisp/tabulated-list.el b/lisp/emacs-lisp/tabulated-list.el
index 63ae1f8c07..4392fbd1e8 100644
--- a/lisp/emacs-lisp/tabulated-list.el
+++ b/lisp/emacs-lisp/tabulated-list.el
@@ -192,6 +192,19 @@ tabulated-list-put-tag
   (if advance
       (forward-line)))
 
+(defun tabulated-list-clear-all-tags ()
+  "Clear all tags from the padding area in the current buffer."
+  (unless (> tabulated-list-padding 0)
+    (error "There can be no tags in current buffer"))
+  (save-excursion
+    (goto-char (point-min))
+    (let ((inhibit-read-only t)
+          ;; Match non-space in the first n characters.
+          (re (format "^ \\{0,%s\\}[^ ]" (1- tabulated-list-padding)))
+          (empty (make-string tabulated-list-padding ? )))
+      (while (re-search-forward re nil 'noerror)
+        (tabulated-list-put-tag empty)))))
+
 (defvar tabulated-list-mode-map
   (let ((map (make-sparse-keymap)))
     (set-keymap-parent map (make-composed-keymap
-- 
2.20.1


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

* bug#37418: [PATCH] Add new function to clear tags in tabulated list
  2019-09-16  1:54 bug#37418: [PATCH] Add new function to clear tags in tabulated list Stefan Kangas
@ 2019-09-20 17:54 ` Lars Ingebrigtsen
  2019-09-26 15:36   ` Stefan Kangas
  0 siblings, 1 reply; 3+ messages in thread
From: Lars Ingebrigtsen @ 2019-09-20 17:54 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: 37418

Stefan Kangas <stefan@marxist.se> writes:

> I found myself wanting to clear all tags in *Packages* buffer, but it
> made more sense to implement this as general functionality in
> tabulated list mode.  How does it look?

[...]

> +(defun tabulated-list-clear-all-tags ()
> +  "Clear all tags from the padding area in the current buffer."
> +  (unless (> tabulated-list-padding 0)
> +    (error "There can be no tags in current buffer"))
> +  (save-excursion
> +    (goto-char (point-min))
> +    (let ((inhibit-read-only t)
> +          ;; Match non-space in the first n characters.
> +          (re (format "^ \\{0,%s\\}[^ ]" (1- tabulated-list-padding)))
> +          (empty (make-string tabulated-list-padding ? )))
> +      (while (re-search-forward re nil 'noerror)
> +        (tabulated-list-put-tag empty)))))

I think it's a good command to add, but I'm not familiar enough with how
tabulated list mode works, so my the only nit-pick I have to add here is
that the %s should be a %d here.  :-)

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





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

* bug#37418: [PATCH] Add new function to clear tags in tabulated list
  2019-09-20 17:54 ` Lars Ingebrigtsen
@ 2019-09-26 15:36   ` Stefan Kangas
  0 siblings, 0 replies; 3+ messages in thread
From: Stefan Kangas @ 2019-09-26 15:36 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 37418-done

Lars Ingebrigtsen <larsi@gnus.org> writes:

> I think it's a good command to add, but I'm not familiar enough with how
> tabulated list mode works, so my the only nit-pick I have to add here is
> that the %s should be a %d here.  :-)

Thanks for taking a look.  Since there have been no further comments
in a week, I have pushed this patch with your suggestion as commit
814cab3b4d.

(I forgot to reference the bug number in the commit message.  Sorry about that.)

Best regards,
Stefan Kangas





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

end of thread, other threads:[~2019-09-26 15:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-16  1:54 bug#37418: [PATCH] Add new function to clear tags in tabulated list Stefan Kangas
2019-09-20 17:54 ` Lars Ingebrigtsen
2019-09-26 15:36   ` Stefan Kangas

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