emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem with let/cl-letf binding stuff with org-capture


From: Arthur Miller
Subject: Re: Problem with let/cl-letf binding stuff with org-capture
Date: Wed, 15 Feb 2023 14:06:12 +0100
User-agent: Gnus/5.13 (Gnus v5.13)

Ihor Radchenko <yantar92@posteo.net> writes:

> Arthur Miller <arthur.miller@live.com> writes:
>
>> Based on a Reddit thread:
>>
>> https://www.reddit.com/r/emacs/comments/10xhvd8/a_little_readstring_utility_using_an_org_mode/j7xziao/?context=3
>>
>> I did a small experiment to see if I can re-use org-capture, to just capture 
>> a
>> string from a buffer, without actually writing to any file.
>
> You can use a template target set to function pointing to temporary
> buffer. + org-capture-before-finalize-hook

I did try something this:

#+begin_src emacs-lisp
(defun my-func ()
  (with-current-buffer (get-buffer-create "my-capture-buffer")))

(defun my-hook ()
  (with-current-buffer 
      (try-completion "CAPTURE" (mapcar #'buffer-name (buffer-list)))
    (let ((content (buffer-string)))
      (kill-buffer)
      content)))

(defun my-read-string ()
  (let ((org-capture-templates
         `(("s" "string" plain (function my-func))))
        (org-capture-before-finalize-hook #'my-hook))
    (org-capture nil "s")))
#+end_src

But that does not work well, because capture will put buffer it is called from
as original buffer and write to that one. To prevent that I can call capture
from a temporary buffer:

#+begin_src emacs-lisp
(defun my-read-string ()
  (with-current-buffer (get-buffer-create "my-capture-buffer")
    (let ((org-capture-templates
           `(("s" "string" plain (function ignore))))
          (org-capture-before-finalize-hook #'my-hook))
      (org-capture nil "s"))))
#+end_src

but than capture complains about the buffer not being a file buffer, despite the
before finalize hook. I could point it to some temp file like /tmp/my-capture, 
by
manipulating capture plist myself, but it seems to be too expensive to create a
temp file just for a hack to read a string form a buffer. There is probably some
other way, but I give up here, especially since you point our
read-string-from-buffer :)

Anyway, thanks for the input and help.

/a



reply via email to

[Prev in Thread] Current Thread [Next in Thread]