unofficial mirror of emacs-orgmode@gnu.org
 help / color / mirror / Atom feed
* [Share] collect some idea about auto eval code when TAB expand headline
@ 2020-10-16  5:01 stardiviner
  2020-10-16 20:45 ` Jeremie Juste
  0 siblings, 1 reply; 3+ messages in thread
From: stardiviner @ 2020-10-16  5:01 UTC (permalink / raw)
  To: Org Mode


I write an elisp config for Org Mode to auto evaluate inline source block in property "EVAL".

#+begin_src emacs-lisp
(defcustom org-property-eval-keywords-list '("EVAL")
  "A list of property keywords for evaluate code."
  :type 'list
  :safe #'listp
  :group 'org)

(defun org-property-eval-code (&optional state)
  "Evaluate Org inline source block in property value."
  (when (memq state '(children subtree))
    (if-let ((inline-src-block (org-entry-get nil "EVAL" nil)))
        (with-temp-buffer
          (insert inline-src-block)
          (goto-char (point-min))
          (require 'ob-async nil t)
          (setq-local org-babel-default-inline-header-args
                      '((:results . "silent") (:async . t)))
          (let* ((context (org-element-context))
                 (src-block-info (org-babel-get-src-block-info nil context))
                 (type (org-element-type context)))
            (when (eq type 'inline-src-block)
              ;; ob-async: `org-babel-execute-src-block:async'
              (org-babel-execute-src-block nil src-block-info)))))))

(add-hook 'org-cycle-hook #'org-property-eval-code)
#+end_src

A question:

How to get all property keywords under headline? I want to use ~member~ to detect
whether property keywords has member in defined custom list
~org-property-eval-keywords-list~.

Second question:

Do you have any good idea or suggest about this?

Thanks for sharing your idea.

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

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


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

* Re: [Share] collect some idea about auto eval code when TAB expand headline
  2020-10-16  5:01 [Share] collect some idea about auto eval code when TAB expand headline stardiviner
@ 2020-10-16 20:45 ` Jeremie Juste
  2020-10-17  0:55   ` stardiviner
  0 siblings, 1 reply; 3+ messages in thread
From: Jeremie Juste @ 2020-10-16 20:45 UTC (permalink / raw)
  To: stardiviner; +Cc: Org Mode


Hello,

I don't see very clearly how you want to use the code.
(It might well be because of my lack of skills)

Could you give a usage example?

Best regards,

Jeremie


On Friday, 16 Oct 2020 at 13:01, stardiviner wrote:
> I write an elisp config for Org Mode to auto evaluate inline source block in property "EVAL".
>
> #+begin_src emacs-lisp
> (defcustom org-property-eval-keywords-list '("EVAL")
>   "A list of property keywords for evaluate code."
>   :type 'list
>   :safe #'listp
>   :group 'org)
>
> (defun org-property-eval-code (&optional state)
>   "Evaluate Org inline source block in property value."
>   (when (memq state '(children subtree))
>     (if-let ((inline-src-block (org-entry-get nil "EVAL" nil)))
>         (with-temp-buffer
>           (insert inline-src-block)
>           (goto-char (point-min))
>           (require 'ob-async nil t)
>           (setq-local org-babel-default-inline-header-args
>                       '((:results . "silent") (:async . t)))
>           (let* ((context (org-element-context))
>                  (src-block-info (org-babel-get-src-block-info nil context))
>                  (type (org-element-type context)))
>             (when (eq type 'inline-src-block)
>               ;; ob-async: `org-babel-execute-src-block:async'
>               (org-babel-execute-src-block nil src-block-info)))))))
>
> (add-hook 'org-cycle-hook #'org-property-eval-code)
> #+end_src
>
> A question:
>
> How to get all property keywords under headline? I want to use ~member~ to detect
> whether property keywords has member in defined custom list
> ~org-property-eval-keywords-list~.
>
> Second question:
>
> Do you have any good idea or suggest about this?
>
> Thanks for sharing your idea.



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

* Re: [Share] collect some idea about auto eval code when TAB expand headline
  2020-10-16 20:45 ` Jeremie Juste
@ 2020-10-17  0:55   ` stardiviner
  0 siblings, 0 replies; 3+ messages in thread
From: stardiviner @ 2020-10-17  0:55 UTC (permalink / raw)
  To: Jeremie Juste; +Cc: Org Mode


Jeremie Juste <jeremiejuste@gmail.com> writes:

> Hello,
>
> I don't see very clearly how you want to use the code.
> (It might well be because of my lack of skills)
>
> Could you give a usage example?

Aha, I forget to copy an example here.

It looks like this.

#+begin_src org
,* 《三生三世 十里桃花》                                              :LOG:TV:
  :PROPERTIES:
  :EVAL: src_sh{mpg123 "三生三世 十里桃花/杨宗纬 张碧晨 - 凉凉.mp3"} 
  :END:

#+end_src

>
> Best regards,
>
> Jeremie
>
>
> On Friday, 16 Oct 2020 at 13:01, stardiviner wrote:
>> I write an elisp config for Org Mode to auto evaluate inline source block in property "EVAL".
>>
>> #+begin_src emacs-lisp
>> (defcustom org-property-eval-keywords-list '("EVAL")
>>   "A list of property keywords for evaluate code."
>>   :type 'list
>>   :safe #'listp
>>   :group 'org)
>>
>> (defun org-property-eval-code (&optional state)
>>   "Evaluate Org inline source block in property value."
>>   (when (memq state '(children subtree))
>>     (if-let ((inline-src-block (org-entry-get nil "EVAL" nil)))
>>         (with-temp-buffer
>>           (insert inline-src-block)
>>           (goto-char (point-min))
>>           (require 'ob-async nil t)
>>           (setq-local org-babel-default-inline-header-args
>>                       '((:results . "silent") (:async . t)))
>>           (let* ((context (org-element-context))
>>                  (src-block-info (org-babel-get-src-block-info nil context))
>>                  (type (org-element-type context)))
>>             (when (eq type 'inline-src-block)
>>               ;; ob-async: `org-babel-execute-src-block:async'
>>               (org-babel-execute-src-block nil src-block-info)))))))
>>
>> (add-hook 'org-cycle-hook #'org-property-eval-code)
>> #+end_src
>>
>> A question:
>>
>> How to get all property keywords under headline? I want to use ~member~ to detect
>> whether property keywords has member in defined custom list
>> ~org-property-eval-keywords-list~.
>>
>> Second question:
>>
>> Do you have any good idea or suggest about this?
>>
>> Thanks for sharing your idea.


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

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


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

end of thread, other threads:[~2020-10-17  0:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-16  5:01 [Share] collect some idea about auto eval code when TAB expand headline stardiviner
2020-10-16 20:45 ` Jeremie Juste
2020-10-17  0:55   ` stardiviner

unofficial mirror of emacs-orgmode@gnu.org

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://yhetil.org/orgmode/0 orgmode/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 orgmode orgmode/ https://yhetil.org/orgmode \
		emacs-orgmode@gnu.org
	public-inbox-index orgmode

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.yhetil.org/yhetil.emacs.orgmode
	nntp://news.gmane.io/gmane.emacs.orgmode


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git