emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* refile captured to all opened Org buffer files as targets
@ 2019-12-25 13:01 stardiviner
  2019-12-25 15:40 ` Ihor Radchenko
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: stardiviner @ 2019-12-25 13:01 UTC (permalink / raw)
  To: Org Mode, Nicolas Goaziou


I recently created an org-capture template for elfeed, it is finished. Now I
have an idea is to refile it to all currently opened Org buffer files. So I
created an function for ~org-refile-targets~ variable.

#+begin_src emacs-lisp
(defun org-refile-targets-all-files ()
  "Use all currently opened Org buffer files as org-refile targets."
  (mapcar 'buffer-file-name
          (seq-filter (lambda (buffer) (if-let (file (buffer-file-name buffer)) (f-ext? file "org"))) ; filter Org buffers
                      (buffer-list))))
#+end_src

Then set ~org-refile-targets~ to use upper custom function

#+begin_src emacs-lisp :eval no
(setq org-refile-targets '((nil :maxlevel . 3) ; current buffer headlies
                           (org-agenda-files :maxlevel . 2) ; agenda files headlines
                           (org-refile-targets-all-files :maxlevel . 3) ; all opened Org buffer files headlines
                           ))
#+end_src

Can I add this as a patch to Org Mode repository?

-- 
[ stardiviner ]
       I try to make every word tell the meaning what I want to express.

       Blog: https://stardiviner.github.io/
       IRC(freenode): stardiviner, Matrix: stardiviner
       GPG: F09F650D7D674819892591401B5DF1C95AE89AC3
      

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

* Re: refile captured to all opened Org buffer files as targets
  2019-12-25 13:01 refile captured to all opened Org buffer files as targets stardiviner
@ 2019-12-25 15:40 ` Ihor Radchenko
  2019-12-27  1:32   ` stardiviner
  2019-12-27  1:17 ` stardiviner
  2019-12-27  6:34 ` Adam Porter
  2 siblings, 1 reply; 7+ messages in thread
From: Ihor Radchenko @ 2019-12-25 15:40 UTC (permalink / raw)
  To: numbchild, Org Mode, Nicolas Goaziou

[offtopic]

> I recently created an org-capture template for elfeed, it is finished. 

Could you share your capture template?


stardiviner <numbchild@gmail.com> writes:

> I recently created an org-capture template for elfeed, it is finished. Now I
> have an idea is to refile it to all currently opened Org buffer files. So I
> created an function for ~org-refile-targets~ variable.
>
> #+begin_src emacs-lisp
> (defun org-refile-targets-all-files ()
>   "Use all currently opened Org buffer files as org-refile targets."
>   (mapcar 'buffer-file-name
>           (seq-filter (lambda (buffer) (if-let (file (buffer-file-name buffer)) (f-ext? file "org"))) ; filter Org buffers
>                       (buffer-list))))
> #+end_src
>
> Then set ~org-refile-targets~ to use upper custom function
>
> #+begin_src emacs-lisp :eval no
> (setq org-refile-targets '((nil :maxlevel . 3) ; current buffer headlies
>                            (org-agenda-files :maxlevel . 2) ; agenda files headlines
>                            (org-refile-targets-all-files :maxlevel . 3) ; all opened Org buffer files headlines
>                            ))
> #+end_src
>
> Can I add this as a patch to Org Mode repository?
>
> -- 
> [ stardiviner ]
>        I try to make every word tell the meaning what I want to express.
>
>        Blog: https://stardiviner.github.io/
>        IRC(freenode): stardiviner, Matrix: stardiviner
>        GPG: F09F650D7D674819892591401B5DF1C95AE89AC3
>       
>

-- 
Ihor Radchenko,
PhD,
Center for Advancing Materials Performance from the Nanoscale (CAMP-nano)
State Key Laboratory for Mechanical Behavior of Materials, Xi'an Jiaotong University, Xi'an, China
Email: yantar92@gmail.com, ihor_radchenko@alumni.sutd.edu.sg

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

* Re: refile captured to all opened Org buffer files as targets
  2019-12-25 13:01 refile captured to all opened Org buffer files as targets stardiviner
  2019-12-25 15:40 ` Ihor Radchenko
@ 2019-12-27  1:17 ` stardiviner
  2019-12-27  6:34 ` Adam Porter
  2 siblings, 0 replies; 7+ messages in thread
From: stardiviner @ 2019-12-27  1:17 UTC (permalink / raw)
  To: Org Mode


I improved command to get ride of =f.el= library function:

#+begin_src emacs-lisp
(defun org-refile-targets-all-files ()
  "Use all currently opened Org buffer files as org-refile targets."
  (mapcar 'buffer-file-name
          (seq-filter ; filter Org buffers
           (lambda (buffer)
             (if-let (file (buffer-file-name buffer))
                 (string-equal (file-name-extension file) "org")
               ;; (f-ext? file "org")
               ))
           (buffer-list))))
#+end_src

Here is the configured option:

#+begin_src emacs-lisp
(setq org-refile-targets '((nil :maxlevel . 3) ; current buffer headlines
                           (org-agenda-files :maxlevel . 2) ; agenda files headlines
                           (org-refile-targets-all-files :maxlevel . 3) ; all opened Org buffer files headlines
                           ))
#+end_src

I think this can be an option for user who might think this is useful like in my
situation. (I want to refile capture elfeed RSS entry to one of my opened Org
buffer's specific headline.)

-- 
[ stardiviner ]
       I try to make every word tell the meaning what I want to express.

       Blog: https://stardiviner.github.io/
       IRC(freenode): stardiviner, Matrix: stardiviner
       GPG: F09F650D7D674819892591401B5DF1C95AE89AC3
      

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

* Re: refile captured to all opened Org buffer files as targets
  2019-12-25 15:40 ` Ihor Radchenko
@ 2019-12-27  1:32   ` stardiviner
  2019-12-27  7:54     ` Ihor Radchenko
  0 siblings, 1 reply; 7+ messages in thread
From: stardiviner @ 2019-12-27  1:32 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Nicolas Goaziou, Org Mode


Ihor Radchenko <yantar92@gmail.com> writes:

> [offtopic]
>
>> I recently created an org-capture template for elfeed, it is finished. 
>
> Could you share your capture template?

Sure, here it is:

#+begin_src emacs-lisp
;; support Org Mode Capture template
(defun my/org-capture-elfeed-title ()
  (with-current-buffer "*elfeed-entry*"
    (elfeed-entry-title elfeed-show-entry)))
(defun my/org-capture-elfeed-date ()
  (with-current-buffer "*elfeed-entry*"
    (format-time-string
     "[%Y-%m-%d %a %H:%M]"
     (seconds-to-time (elfeed-entry-date elfeed-show-entry)))))
(defun my/org-capture-elfeed-source ()
  (with-current-buffer "*elfeed-entry*"
    (let ((feed (elfeed-entry-feed elfeed-show-entry)))
      (elfeed-feed-title feed))))
(defun my/org-capture-elfeed-content ()
  (with-current-buffer "*elfeed-entry*"
    (let* ((content (elfeed-deref (elfeed-entry-content elfeed-show-entry)))
           (type (elfeed-entry-content-type elfeed-show-entry))
           (feed (elfeed-entry-feed elfeed-show-entry))
           (base-url (and feed (elfeed-compute-base (elfeed-feed-url feed)))))
      (if content
          (if (eq type 'html)
              (org-web-tools--html-to-org-with-pandoc content)
            (insert content))))))

(add-to-list 'org-capture-templates
             '("R" "Capture elfeed [R]SS feed content to Org buffer"
               entry (file "")
               "* %(my/org-capture-elfeed-title)
:PROPERTIES:
:SOURCE: %(my/org-capture-elfeed-source)
:DATE(original): %(my/org-capture-elfeed-date)
:DATE: %u
:END:

%(my/org-capture-elfeed-content)"
               :empty-lines 1
               :jump-to-captured t))
#+end_src

If possible, I might submit this PR to elfeed.el repository.

-- 
[ stardiviner ]
       I try to make every word tell the meaning what I want to express.

       Blog: https://stardiviner.github.io/
       IRC(freenode): stardiviner, Matrix: stardiviner
       GPG: F09F650D7D674819892591401B5DF1C95AE89AC3
      

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

* Re: refile captured to all opened Org buffer files as targets
  2019-12-25 13:01 refile captured to all opened Org buffer files as targets stardiviner
  2019-12-25 15:40 ` Ihor Radchenko
  2019-12-27  1:17 ` stardiviner
@ 2019-12-27  6:34 ` Adam Porter
  2019-12-27 14:10   ` stardiviner
  2 siblings, 1 reply; 7+ messages in thread
From: Adam Porter @ 2019-12-27  6:34 UTC (permalink / raw)
  To: emacs-orgmode

stardiviner <numbchild@gmail.com> writes:

> I recently created an org-capture template for elfeed, it is finished. Now I
> have an idea is to refile it to all currently opened Org buffer files. So I
> created an function for ~org-refile-targets~ variable.
>
> #+begin_src emacs-lisp
> (defun org-refile-targets-all-files ()
>   "Use all currently opened Org buffer files as org-refile targets."
>   (mapcar 'buffer-file-name
>           (seq-filter (lambda (buffer) (if-let (file (buffer-file-name buffer)) (f-ext? file "org"))) ; filter Org buffers
>                       (buffer-list))))
> #+end_src
>
>
> Then set ~org-refile-targets~ to use upper custom function
>
> #+begin_src emacs-lisp :eval no
> (setq org-refile-targets '((nil :maxlevel . 3) ; current buffer headlies
>                            (org-agenda-files :maxlevel . 2) ; agenda files headlines
>                            (org-refile-targets-all-files :maxlevel . 3) ; all opened Org buffer files headlines
>                            ))
> #+end_src
>
> Can I add this as a patch to Org Mode repository?

    org-buffer-list is a compiled Lisp function in ‘org.el’.

    (org-buffer-list &optional PREDICATE EXCLUDE-TMP)

    Return a list of Org buffers.
    PREDICATE can be ‘export’, ‘files’ or ‘agenda’.

    export   restrict the list to Export buffers.
    files    restrict the list to buffers visiting Org files.
    agenda   restrict the list to buffers visiting agenda files.

    If EXCLUDE-TMP is non-nil, ignore temporary buffers.

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

* Re: refile captured to all opened Org buffer files as targets
  2019-12-27  1:32   ` stardiviner
@ 2019-12-27  7:54     ` Ihor Radchenko
  0 siblings, 0 replies; 7+ messages in thread
From: Ihor Radchenko @ 2019-12-27  7:54 UTC (permalink / raw)
  To: stardiviner; +Cc: Nicolas Goaziou, Org Mode

Thanks!

org-web-tools--html-to-org-with-pandoc is an interesting idea. I was
using elfeed-insert-html for this purpose.

Also, note that your capture may be messed up when the rss content
contains org-mode text. A real-case scenario from Stack Exchange rss: 

> I'd like to find a way to jump to a location in an org-mode file while automatically unfolding only the heading at the location I'm jumping to and all its parent headings (but not any sibling headings).
> 
> For example, if I have this org-mode file:
> 
> * A
> ** AA

If you insert the rss entry contents as is, two unexpected headings will
be created.

I use the following to escape possible org-mode text:

                      (setq content-text (with-temp-buffer (when content
							     (if (eq content-type 'html)
								 (elfeed-insert-html content)
							       (insert content)))
							   (let ((org-babel-min-lines-for-block-output 0)) ;; handle org-mode syntax in body
							     (org-escape-code-in-region (point-min) (point-max)))
							   (buffer-string)))

Best,
Ihor


stardiviner <numbchild@gmail.com> writes:

> Ihor Radchenko <yantar92@gmail.com> writes:
>
>> [offtopic]
>>
>>> I recently created an org-capture template for elfeed, it is finished. 
>>
>> Could you share your capture template?
>
> Sure, here it is:
>
> #+begin_src emacs-lisp
> ;; support Org Mode Capture template
> (defun my/org-capture-elfeed-title ()
>   (with-current-buffer "*elfeed-entry*"
>     (elfeed-entry-title elfeed-show-entry)))
> (defun my/org-capture-elfeed-date ()
>   (with-current-buffer "*elfeed-entry*"
>     (format-time-string
>      "[%Y-%m-%d %a %H:%M]"
>      (seconds-to-time (elfeed-entry-date elfeed-show-entry)))))
> (defun my/org-capture-elfeed-source ()
>   (with-current-buffer "*elfeed-entry*"
>     (let ((feed (elfeed-entry-feed elfeed-show-entry)))
>       (elfeed-feed-title feed))))
> (defun my/org-capture-elfeed-content ()
>   (with-current-buffer "*elfeed-entry*"
>     (let* ((content (elfeed-deref (elfeed-entry-content elfeed-show-entry)))
>            (type (elfeed-entry-content-type elfeed-show-entry))
>            (feed (elfeed-entry-feed elfeed-show-entry))
>            (base-url (and feed (elfeed-compute-base (elfeed-feed-url feed)))))
>       (if content
>           (if (eq type 'html)
>               (org-web-tools--html-to-org-with-pandoc content)
>             (insert content))))))
>
> (add-to-list 'org-capture-templates
>              '("R" "Capture elfeed [R]SS feed content to Org buffer"
>                entry (file "")
>                "* %(my/org-capture-elfeed-title)
> :PROPERTIES:
> :SOURCE: %(my/org-capture-elfeed-source)
> :DATE(original): %(my/org-capture-elfeed-date)
> :DATE: %u
> :END:
>
> %(my/org-capture-elfeed-content)"
>                :empty-lines 1
>                :jump-to-captured t))
> #+end_src
>
> If possible, I might submit this PR to elfeed.el repository.
>
> -- 
> [ stardiviner ]
>        I try to make every word tell the meaning what I want to express.
>
>        Blog: https://stardiviner.github.io/
>        IRC(freenode): stardiviner, Matrix: stardiviner
>        GPG: F09F650D7D674819892591401B5DF1C95AE89AC3
>       

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

* Re: refile captured to all opened Org buffer files as targets
  2019-12-27  6:34 ` Adam Porter
@ 2019-12-27 14:10   ` stardiviner
  0 siblings, 0 replies; 7+ messages in thread
From: stardiviner @ 2019-12-27 14:10 UTC (permalink / raw)
  To: emacs-orgmode


Adam Porter <adam@alphapapa.net> writes:

>     org-buffer-list is a compiled Lisp function in ‘org.el’.
>
>     (org-buffer-list &optional PREDICATE EXCLUDE-TMP)
>
>     Return a list of Org buffers.
>     PREDICATE can be ‘export’, ‘files’ or ‘agenda’.
>
>     export   restrict the list to Export buffers.
>     files    restrict the list to buffers visiting Org files.
>     agenda   restrict the list to buffers visiting agenda files.
>
>     If EXCLUDE-TMP is non-nil, ignore temporary buffers.

This is very awesome, thanks! :)

-- 
[ stardiviner ]
       I try to make every word tell the meaning what I want to express.

       Blog: https://stardiviner.github.io/
       IRC(freenode): stardiviner, Matrix: stardiviner
       GPG: F09F650D7D674819892591401B5DF1C95AE89AC3
      

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

end of thread, other threads:[~2019-12-27 14:10 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-25 13:01 refile captured to all opened Org buffer files as targets stardiviner
2019-12-25 15:40 ` Ihor Radchenko
2019-12-27  1:32   ` stardiviner
2019-12-27  7:54     ` Ihor Radchenko
2019-12-27  1:17 ` stardiviner
2019-12-27  6:34 ` Adam Porter
2019-12-27 14:10   ` stardiviner

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