emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [Worg] Addition to org-hacks: Remove redundant tags
@ 2010-01-25 19:23 David Maus
  2010-01-26  5:34 ` Manish
  0 siblings, 1 reply; 4+ messages in thread
From: David Maus @ 2010-01-25 19:23 UTC (permalink / raw)
  To: Emacs Orgmode Mailinglist


[-- Attachment #1.1.1: Type: text/plain, Size: 1423 bytes --]

Hello,

Attached patch adds a section to the org-hacks page of Worg with a
function that removes redundant tags, that is: tags that are inherited
by a parent headline or the #+FILETAGS headline and local to a
headline.

This function is useful for me as I generally use tags to denote a
todo's context (priv for private, work for work related etc.) and in
addition split my agenda files by context, too (work.org,
private.org). If I file new todo headlines using `org-remember' they
go in a central file (bucket.org) and I tag them so they show up on
tags searches.  After refiling the context denoting tags are
duplicated -- hence I wrote this little function to remove them:

(defun dmj/org-remove-redundant-tags ()
  "Remove redundant tags of headlines in current buffer.

  A tag is considered redundant if it is local to a headline and
  inherited by a parent headline."
  (interactive)
  (when (eq major-mode 'org-mode)
    (save-excursion
      (org-map-entries
       '(lambda ()
	  (let ((alltags (split-string (org-entry-get (point) "ALLTAGS") ":"))
		local inherited tag)
	    (dolist (tag alltags)
	      (if (get-text-property 0 'inherited tag)
		  (push tag inherited) (push tag local)))
	    (dolist (tag local)
	      (if (member tag inherited) (org-toggle-tag tag 'off)))))
       t nil))))

Regards

 -- David

--
OpenPGP... 0x99ADB83B5A4478E6
Jabber.... dmjena@jabber.org
Email..... maus.david@gmail.com

[-- Attachment #1.1.2: 0001-org-hacks-Remove-redundant-tags-i.e.-tags-that-are-i.patch --]
[-- Type: application/octet-stream, Size: 1690 bytes --]

From 238f79b75373e86de1fc347fbb759b1456b438f6 Mon Sep 17 00:00:00 2001
From: David Maus <maus.david@gmail.com>
Date: Mon, 25 Jan 2010 19:24:44 +0100
Subject: [PATCH] org-hacks: Remove redundant tags (i.e. tags that are inherited and
 local) of headlines

---
 org-hacks.org |   28 ++++++++++++++++++++++++++++
 1 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/org-hacks.org b/org-hacks.org
index 2b8fa57..6d0c915 100644
--- a/org-hacks.org
+++ b/org-hacks.org
@@ -841,3 +841,31 @@ using ido):
 To browse your org attachments using ido fuzzy matching and/or the
 completion buffer, invoke ido-find-file as usual (=C-x C-f=) and then
 press =C-;=.
+
+* Remove redundant tags of headlines
+  -- David Maus
+
+A small function that processes all headlines in current buffer and
+removes tags that are local to a headline and inherited by a parent
+headline or the #+FILETAGS: statement.
+
+#+BEGIN_SRC emacs-lisp
+  (defun dmj/org-remove-redundant-tags ()
+    "Remove redundant tags of headlines in current buffer.
+  
+  A tag is considered redundant if it is local to a headline and
+  inherited by a parent headline."
+    (interactive)
+    (when (eq major-mode 'org-mode)
+      (save-excursion
+        (org-map-entries 
+         '(lambda ()
+            (let ((alltags (split-string (org-entry-get (point) "ALLTAGS") ":"))
+                  local inherited tag)
+              (dolist (tag alltags)
+                (if (get-text-property 0 'inherited tag)
+                    (push tag inherited) (push tag local)))
+              (dolist (tag local)
+                (if (member tag inherited) (org-toggle-tag tag 'off)))))
+         t nil))))
+#+END_SRC
-- 
1.6.5


[-- Attachment #1.2: Type: application/pgp-signature, Size: 230 bytes --]

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

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

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

* Re: [Worg] Addition to org-hacks: Remove redundant tags
  2010-01-25 19:23 [Worg] Addition to org-hacks: Remove redundant tags David Maus
@ 2010-01-26  5:34 ` Manish
  2010-01-26 16:22   ` David Maus
  0 siblings, 1 reply; 4+ messages in thread
From: Manish @ 2010-01-26  5:34 UTC (permalink / raw)
  To: David Maus; +Cc: Emacs Orgmode Mailinglist

Applied to Worg.

Thanks
-- 
Manish

On Tue, Jan 26, 2010 at 12:53 AM, David Maus wrote:
> Hello,
>
> Attached patch adds a section to the org-hacks page of Worg with a
> function that removes redundant tags, that is: tags that are inherited
> by a parent headline or the #+FILETAGS headline and local to a
> headline.
>
> This function is useful for me as I generally use tags to denote a
> todo's context (priv for private, work for work related etc.) and in
> addition split my agenda files by context, too (work.org,
> private.org). If I file new todo headlines using `org-remember' they
> go in a central file (bucket.org) and I tag them so they show up on
> tags searches.  After refiling the context denoting tags are
> duplicated -- hence I wrote this little function to remove them:
>
> (defun dmj/org-remove-redundant-tags ()
>  "Remove redundant tags of headlines in current buffer.
>
>  A tag is considered redundant if it is local to a headline and
>  inherited by a parent headline."
>  (interactive)
>  (when (eq major-mode 'org-mode)
>    (save-excursion
>      (org-map-entries
>       '(lambda ()
>          (let ((alltags (split-string (org-entry-get (point) "ALLTAGS") ":"))
>                local inherited tag)
>            (dolist (tag alltags)
>              (if (get-text-property 0 'inherited tag)
>                  (push tag inherited) (push tag local)))
>            (dolist (tag local)
>              (if (member tag inherited) (org-toggle-tag tag 'off)))))
>       t nil))))
>
> Regards
>
>  -- David
>
> --
> OpenPGP... 0x99ADB83B5A4478E6
> Jabber.... dmjena@jabber.org
> Email..... maus.david@gmail.com
>
> _______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode
>
>

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

* Re: [Worg] Addition to org-hacks: Remove redundant tags
  2010-01-26  5:34 ` Manish
@ 2010-01-26 16:22   ` David Maus
  2010-01-26 16:54     ` Manish
  0 siblings, 1 reply; 4+ messages in thread
From: David Maus @ 2010-01-26 16:22 UTC (permalink / raw)
  To: Manish; +Cc: Emacs Orgmode Mailinglist


[-- Attachment #1.1.1: Type: text/plain, Size: 302 bytes --]

At Tue, 26 Jan 2010 11:04:06 +0530,
Manish wrote:
>
> Applied to Worg.
>
> Thanks

Ooops, attached patch fixes a small glitch in this function that
prevented it working on headlines without tags.

 -- David

--
OpenPGP... 0x99ADB83B5A4478E6
Jabber.... dmjena@jabber.org
Email..... maus.david@gmail.com

[-- Attachment #1.1.2: 0001-fix-small-glitch-in-dmj-org-remove-redundant-tags.patch --]
[-- Type: application/octet-stream, Size: 859 bytes --]

From 234f58218da08119432212dfe16bbe649b4c9827 Mon Sep 17 00:00:00 2001
From: David Maus <maus.david@gmail.com>
Date: Tue, 26 Jan 2010 17:21:26 +0100
Subject: [PATCH] fix small glitch in dmj/org-remove-redundant-tags

---
 org-hacks.org |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/org-hacks.org b/org-hacks.org
index 6d0c915..76a7dcd 100644
--- a/org-hacks.org
+++ b/org-hacks.org
@@ -860,7 +860,7 @@ headline or the #+FILETAGS: statement.
       (save-excursion
         (org-map-entries 
          '(lambda ()
-            (let ((alltags (split-string (org-entry-get (point) "ALLTAGS") ":"))
+            (let ((alltags (split-string (or (org-entry-get (point) "ALLTAGS") "") ":"))
                   local inherited tag)
               (dolist (tag alltags)
                 (if (get-text-property 0 'inherited tag)
-- 
1.6.5


[-- Attachment #1.2: Type: application/pgp-signature, Size: 230 bytes --]

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

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

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

* Re: [Worg] Addition to org-hacks: Remove redundant tags
  2010-01-26 16:22   ` David Maus
@ 2010-01-26 16:54     ` Manish
  0 siblings, 0 replies; 4+ messages in thread
From: Manish @ 2010-01-26 16:54 UTC (permalink / raw)
  To: David Maus; +Cc: Emacs Orgmode Mailinglist

On Tue, Jan 26, 2010 at 9:52 PM, David Maus wrote:
> At Tue, 26 Jan 2010 11:04:06 +0530,
> Manish wrote:
>>
>> Applied to Worg.
>>
>> Thanks
>
> Ooops, attached patch fixes a small glitch in this function that
> prevented it working on headlines without tags.

Applied to Worg.

Thanks
-- 
Manish

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

end of thread, other threads:[~2010-01-26 16:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-01-25 19:23 [Worg] Addition to org-hacks: Remove redundant tags David Maus
2010-01-26  5:34 ` Manish
2010-01-26 16:22   ` David Maus
2010-01-26 16:54     ` Manish

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.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).