emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Kill all items with specific tag to kill-ring.
@ 2013-04-25  5:32 Oleksandr Gavenko
  2013-04-25  6:37 ` Carsten Dominik
  0 siblings, 1 reply; 10+ messages in thread
From: Oleksandr Gavenko @ 2013-04-25  5:32 UTC (permalink / raw)
  To: emacs-orgmode

I use tags only on top level items in org-file.

And want move all items marked by specific tag to different org-file.

I expect that this command kill items with selected tag to kill-ring in one
step (so single undo command return original buffer content).

Seems there are no such command build-in command...

-- 
Best regards!

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

* Re: Kill all items with specific tag to kill-ring.
  2013-04-25  5:32 Kill all items with specific tag to kill-ring Oleksandr Gavenko
@ 2013-04-25  6:37 ` Carsten Dominik
  2013-04-25  8:21   ` Oleksandr Gavenko
  0 siblings, 1 reply; 10+ messages in thread
From: Carsten Dominik @ 2013-04-25  6:37 UTC (permalink / raw)
  To: Oleksandr Gavenko; +Cc: emacs-orgmode

On 25.4.2013, at 07:32, Oleksandr Gavenko <gavenkoa@gmail.com> wrote:

> I use tags only on top level items in org-file.
> 
> And want move all items marked by specific tag to different org-file.
> 
> I expect that this command kill items with selected tag to kill-ring in one
> step (so single undo command return original buffer content).
> 
> Seems there are no such command build-in command...

no, but you could easily make one using the function org-map-entries.


- Carsten

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

* Re: Kill all items with specific tag to kill-ring.
  2013-04-25  6:37 ` Carsten Dominik
@ 2013-04-25  8:21   ` Oleksandr Gavenko
  2013-04-25  8:36     ` Carsten Dominik
  0 siblings, 1 reply; 10+ messages in thread
From: Oleksandr Gavenko @ 2013-04-25  8:21 UTC (permalink / raw)
  To: emacs-orgmode

Carsten Dominik <carsten.dominik <at> gmail.com> writes:

> 
> On 25.4.2013, at 07:32, Oleksandr Gavenko <gavenkoa <at> gmail.com> wrote:
> 
> > I use tags only on top level items in org-file.
> > 
> > And want move all items marked by specific tag to different org-file.
> > 
> > I expect that this command kill items with selected tag to kill-ring in one
> > step (so single undo command return original buffer content).
> > 
> > Seems there are no such command build-in command...
> 
> no, but you could easily make one using the function org-map-entries.
> 

I finish with very hackie code (based on knowledge of internal
implementation of org-scan-tags):

(defun my-org-kill-by-tag (tag)
  (interactive (list (read-input "Enter tag: ")))
  (kill-new "")
  (org-scan-tags
   (lambda ()
     (let ( (last-command 'kill-region) )
       (org-cut-subtree)))
   '(member tag tags-list)
   nil) )

You can replace 'org-cut-subtree' by 'org-copy-subtree' if don't want remove
org entries...

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

* Re: Kill all items with specific tag to kill-ring.
  2013-04-25  8:21   ` Oleksandr Gavenko
@ 2013-04-25  8:36     ` Carsten Dominik
  2013-04-25  8:56       ` Oleksandr Gavenko
  0 siblings, 1 reply; 10+ messages in thread
From: Carsten Dominik @ 2013-04-25  8:36 UTC (permalink / raw)
  To: Oleksandr Gavenko; +Cc: emacs-orgmode


On 25.4.2013, at 10:21, Oleksandr Gavenko <gavenkoa@gmail.com> wrote:

> Carsten Dominik <carsten.dominik <at> gmail.com> writes:
> 
>> 
>> On 25.4.2013, at 07:32, Oleksandr Gavenko <gavenkoa <at> gmail.com> wrote:
>> 
>>> I use tags only on top level items in org-file.
>>> 
>>> And want move all items marked by specific tag to different org-file.
>>> 
>>> I expect that this command kill items with selected tag to kill-ring in one
>>> step (so single undo command return original buffer content).
>>> 
>>> Seems there are no such command build-in command...
>> 
>> no, but you could easily make one using the function org-map-entries.
>> 
> 
> I finish with very hackie code (based on knowledge of internal
> implementation of org-scan-tags):
> 
> (defun my-org-kill-by-tag (tag)
>  (interactive (list (read-input "Enter tag: ")))
>  (kill-new "")
>  (org-scan-tags
>   (lambda ()
>     (let ( (last-command 'kill-region) )
>       (org-cut-subtree)))
>   '(member tag tags-list)
>   nil) )
> 
> You can replace 'org-cut-subtree' by 'org-copy-subtree' if don't want remove
> org entries...

Yes, this work, nice trick with binding last-command to kill-region.

A less hackie version would probably add the found entries to a
string or list and only put that string into the kill ring at the end.

org-map-entries would allow processing of several files in one go,
but it would be a very similar implementation.

- Carsten

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

* Re: Kill all items with specific tag to kill-ring.
  2013-04-25  8:36     ` Carsten Dominik
@ 2013-04-25  8:56       ` Oleksandr Gavenko
  2013-04-25 10:49         ` Carsten Dominik
  0 siblings, 1 reply; 10+ messages in thread
From: Oleksandr Gavenko @ 2013-04-25  8:56 UTC (permalink / raw)
  To: emacs-orgmode

Carsten Dominik <carsten.dominik <at> gmail.com> writes:

> 
> 
> On 25.4.2013, at 10:21, Oleksandr Gavenko <gavenkoa <at> gmail.com> wrote:
> 
> > I finish with very hackie code (based on knowledge of internal
> > implementation of org-scan-tags):
> > 
> > (defun my-org-kill-by-tag (tag)
> >  (interactive (list (read-input "Enter tag: ")))
> >  (kill-new "")
> >  (org-scan-tags
> >   (lambda ()
> >     (let ( (last-command 'kill-region) )
> >       (org-cut-subtree)))
> >   '(member tag tags-list)
> >   nil) )
> > 
> > You can replace 'org-cut-subtree' by 'org-copy-subtree' if don't want remove
> > org entries...
> 
> Yes, this work, nice trick with binding last-command to kill-region.
> 

10 min of reading (info "(elisp)Low-Level Kill Ring")... This morning I ask:

  http://thread.gmane.org/gmane.emacs.help/90339
        Want to delete distinct regions but make capable undo by single command.

This hack based on:

   (defun kill-region (beg end &optional yank-handler)
     ....
	  (if (eq last-command 'kill-region)
	      (kill-append string (< end beg) yank-handler)
	    (kill-new string nil yank-handler)))

> A less hackie version would probably add the found entries to a
> string or list and only put that string into the kill ring at the end.
> 
> org-map-entries would allow processing of several files in one go,
> but it would be a very similar implementation.
> 

I look to code and found that 'org-map-entries' call 'org-scan-tags'. As
'org-map-entries' looks complicated to me I try to use more low-level
function...

'org-map-entries' also allow rich search queries:

  (info "(org)Matching tags and properties")

`+work-boss'
     Select headlines tagged `:work:', but discard those also tagged
     `:boss:'.

`work|laptop'
     Selects lines tagged `:work:' or `:laptop:'.

`work|laptop+night'
     Like before, but require the `:laptop:' lines to be tagged also
     `:night:'.

Next 20 min I search for 'org-get-buffer-tags'. This code completely satisfy
my needs:

(defun my-org-kill-by-tag (tag)
  (interactive (list (completing-read "Enter tag: " (org-get-buffer-tags))))
  (kill-new "")
  (org-scan-tags
   (lambda ()
     (let ( (last-command 'kill-region) )
       (org-cut-subtree)))
   '(member tag tags-list)
   nil) )

Is it possible to include "correct" implementation (seems that I can't able
implement one) to org-mode?

I want this feature in order to simplify precess of moving entries from job
org-file to home org-file by marking entries with tag :HOME:...

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

* Re: Kill all items with specific tag to kill-ring.
  2013-04-25  8:56       ` Oleksandr Gavenko
@ 2013-04-25 10:49         ` Carsten Dominik
  2013-04-25 11:06           ` Oleksandr Gavenko
  0 siblings, 1 reply; 10+ messages in thread
From: Carsten Dominik @ 2013-04-25 10:49 UTC (permalink / raw)
  To: Oleksandr Gavenko; +Cc: emacs-orgmode


On 25 apr. 2013, at 10:56, Oleksandr Gavenko <gavenkoa@gmail.com> wrote:

> Carsten Dominik <carsten.dominik <at> gmail.com> writes:
> 
>> 
>> 
>> On 25.4.2013, at 10:21, Oleksandr Gavenko <gavenkoa <at> gmail.com> wrote:
>> 
>>> I finish with very hackie code (based on knowledge of internal
>>> implementation of org-scan-tags):
>>> 
>>> (defun my-org-kill-by-tag (tag)
>>> (interactive (list (read-input "Enter tag: ")))
>>> (kill-new "")
>>> (org-scan-tags
>>>  (lambda ()
>>>    (let ( (last-command 'kill-region) )
>>>      (org-cut-subtree)))
>>>  '(member tag tags-list)
>>>  nil) )
>>> 
>>> You can replace 'org-cut-subtree' by 'org-copy-subtree' if don't want remove
>>> org entries...
>> 
>> Yes, this work, nice trick with binding last-command to kill-region.
>> 
> 
> 10 min of reading (info "(elisp)Low-Level Kill Ring")... This morning I ask:
> 
>  http://thread.gmane.org/gmane.emacs.help/90339
>        Want to delete distinct regions but make capable undo by single command.
> 
> This hack based on:
> 
>   (defun kill-region (beg end &optional yank-handler)
>     ....
> 	  (if (eq last-command 'kill-region)
> 	      (kill-append string (< end beg) yank-handler)
> 	    (kill-new string nil yank-handler)))
> 
>> A less hackie version would probably add the found entries to a
>> string or list and only put that string into the kill ring at the end.
>> 
>> org-map-entries would allow processing of several files in one go,
>> but it would be a very similar implementation.
>> 
> 
> I look to code and found that 'org-map-entries' call 'org-scan-tags'. As
> 'org-map-entries' looks complicated to me I try to use more low-level
> function...
> 
> 'org-map-entries' also allow rich search queries:
> 
>  (info "(org)Matching tags and properties")
> 
> `+work-boss'
>     Select headlines tagged `:work:', but discard those also tagged
>     `:boss:'.
> 
> `work|laptop'
>     Selects lines tagged `:work:' or `:laptop:'.
> 
> `work|laptop+night'
>     Like before, but require the `:laptop:' lines to be tagged also
>     `:night:'.
> 
> Next 20 min I search for 'org-get-buffer-tags'. This code completely satisfy
> my needs:
> 
> (defun my-org-kill-by-tag (tag)
>  (interactive (list (completing-read "Enter tag: " (org-get-buffer-tags))))
>  (kill-new "")
>  (org-scan-tags
>   (lambda ()
>     (let ( (last-command 'kill-region) )
>       (org-cut-subtree)))
>   '(member tag tags-list)
>   nil) )
> 
> Is it possible to include "correct" implementation (seems that I can't able
> implement one) to org-mode?


I thought your version did work?  Does it not?

- Carsten

> 
> I want this feature in order to simplify precess of moving entries from job
> org-file to home org-file by marking entries with tag :HOME:...
> 
> 

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

* Re: Kill all items with specific tag to kill-ring.
  2013-04-25 10:49         ` Carsten Dominik
@ 2013-04-25 11:06           ` Oleksandr Gavenko
  2013-04-25 11:48             ` Bernt Hansen
  0 siblings, 1 reply; 10+ messages in thread
From: Oleksandr Gavenko @ 2013-04-25 11:06 UTC (permalink / raw)
  To: emacs-orgmode

Carsten Dominik <carsten.dominik <at> gmail.com> writes:

> On 25 apr. 2013, at 10:56, Oleksandr Gavenko <gavenkoa <at> gmail.com> wrote:
> > 
> > (defun my-org-kill-by-tag (tag)
> >  (interactive (list (completing-read "Enter tag: " (org-get-buffer-tags))))
> >  (kill-new "")
> >  (org-scan-tags
> >   (lambda ()
> >     (let ( (last-command 'kill-region) )
> >       (org-cut-subtree)))
> >   '(member tag tags-list)
> >   nil) )
> > 
> > Is it possible to include "correct" implementation (seems that I can't able
> > implement one) to org-mode?
> 
> I thought your version did work?  Does it not?
> 

Yes. It works. But implementation relay on internals of 'org-cut-subtree' 
and applied only to single file and without any checks (I try call on
non-org buffer - it doesn't do anything - so seems it is safe).

Also it doesn't follow any org-mode coding conventions...

Also 'org-scan-tags' have 'todo-only' argument which may be interesting for
possible users of my-org-kill-by-tag....

> > I want this feature in order to simplify precess of moving entries from job
> > org-file to home org-file by marking entries with tag :HOME:...

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

* Re: Kill all items with specific tag to kill-ring.
  2013-04-25 11:06           ` Oleksandr Gavenko
@ 2013-04-25 11:48             ` Bernt Hansen
  2013-04-29 17:14               ` Oleksandr Gavenko
  0 siblings, 1 reply; 10+ messages in thread
From: Bernt Hansen @ 2013-04-25 11:48 UTC (permalink / raw)
  To: Oleksandr Gavenko; +Cc: emacs-orgmode

Oleksandr Gavenko <gavenkoa@gmail.com> writes:

>> > I want this feature in order to simplify precess of moving entries from job
>> > org-file to home org-file by marking entries with tag :HOME:...

Hi Oleksandr,

If all you want to do is move items why not use the agenda?  Mark your
entries with a tag, do an agenda search for that tag, mark all entries
with m and move them using bulk refile with B r

Regards,
Bernt

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

* Re: Kill all items with specific tag to kill-ring.
  2013-04-25 11:48             ` Bernt Hansen
@ 2013-04-29 17:14               ` Oleksandr Gavenko
  2013-05-01 20:51                 ` Carsten Dominik
  0 siblings, 1 reply; 10+ messages in thread
From: Oleksandr Gavenko @ 2013-04-29 17:14 UTC (permalink / raw)
  To: emacs-orgmode

On 2013-04-25, Bernt Hansen wrote:

> Oleksandr Gavenko <gavenkoa@gmail.com> writes:
>
>>> > I want this feature in order to simplify precess of moving entries from
>>> > job org-file to home org-file by marking entries with tag :HOME:...
>
> If all you want to do is move items why not use the agenda? Mark your
> entries with a tag, do an agenda search for that tag, mark all entries with
> m and move them using bulk refile with B r
>
Great! I don't often use agenda so don't know about this feature.

How can I select specific buffer/file (and only this buffer) for
displaying/processing in agenda?

-- 
Best regards!

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

* Re: Kill all items with specific tag to kill-ring.
  2013-04-29 17:14               ` Oleksandr Gavenko
@ 2013-05-01 20:51                 ` Carsten Dominik
  0 siblings, 0 replies; 10+ messages in thread
From: Carsten Dominik @ 2013-05-01 20:51 UTC (permalink / raw)
  To: Oleksandr Gavenko; +Cc: emacs-orgmode


On 29.4.2013, at 19:14, Oleksandr Gavenko <gavenkoa@gmail.com> wrote:

> On 2013-04-25, Bernt Hansen wrote:
> 
>> Oleksandr Gavenko <gavenkoa@gmail.com> writes:
>> 
>>>>> I want this feature in order to simplify precess of moving entries from
>>>>> job org-file to home org-file by marking entries with tag :HOME:...
>> 
>> If all you want to do is move items why not use the agenda? Mark your
>> entries with a tag, do an agenda search for that tag, mark all entries with
>> m and move them using bulk refile with B r
>> 
> Great! I don't often use agenda so don't know about this feature.
> 
> How can I select specific buffer/file (and only this buffer) for
> displaying/processing in agenda?


You call the agenda from that buffer and press "1" or "<" once after
`C-c a' and before the agenda command key, for example

C-c a < m

for a match view.

- Carsten

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

end of thread, other threads:[~2013-05-01 20:51 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-25  5:32 Kill all items with specific tag to kill-ring Oleksandr Gavenko
2013-04-25  6:37 ` Carsten Dominik
2013-04-25  8:21   ` Oleksandr Gavenko
2013-04-25  8:36     ` Carsten Dominik
2013-04-25  8:56       ` Oleksandr Gavenko
2013-04-25 10:49         ` Carsten Dominik
2013-04-25 11:06           ` Oleksandr Gavenko
2013-04-25 11:48             ` Bernt Hansen
2013-04-29 17:14               ` Oleksandr Gavenko
2013-05-01 20:51                 ` Carsten Dominik

Code repositories for project(s) associated with this 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).