emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Turn function into interactive
@ 2019-12-30  5:26 Lawrence Bottorff
  2019-12-30 18:43 ` Berry, Charles
  0 siblings, 1 reply; 2+ messages in thread
From: Lawrence Bottorff @ 2019-12-30  5:26 UTC (permalink / raw)
  To: emacs-orgmode Mailinglist

[-- Attachment #1: Type: text/plain, Size: 946 bytes --]

I've discovered org-outline-level which when in a code block under a given
header delivers as expected:

* This old level
#+BEGIN_SRC emacs-lisp
(org-current-level)
#+END_SRC

#+RESULTS:
: 1

Now, how could I turn this into an interactive callable with M-x? My stab
in the dark

(defun my-insert-level ()
  (interactive)
  (insert (org-outline-level)))

doesn't seem to be working. Or is there already an interactive that will
give me what level I'm at? My goal is to put this into a tempo template for
a PROPERTIES key-value, and I assume this sort of construct

(tempo-define-template "org-PROPERTIES_time-uuid-level"
'(":PROPERTIES:" n
":HLEVEL: " (my-insert-level) n
":Time: " (my-insert-dateutc) n
":UUID: " (my-insert-uuid) n
":END:" )
      "<Pt" "Insert PROPERTIES time-uuid-level block" 'org-tempo-tags)

which gets distorted-munged, no doubt because it doesn't properly call
and/or return org-outline-level. Any hints appreciated.


LB

[-- Attachment #2: Type: text/html, Size: 1774 bytes --]

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

* Re: Turn function into interactive
  2019-12-30  5:26 Turn function into interactive Lawrence Bottorff
@ 2019-12-30 18:43 ` Berry, Charles
  0 siblings, 0 replies; 2+ messages in thread
From: Berry, Charles @ 2019-12-30 18:43 UTC (permalink / raw)
  To: Lawrence Bottorff; +Cc: emacs-orgmode Mailinglist



> On Dec 29, 2019, at 9:26 PM, Lawrence Bottorff <borgauf@gmail.com> wrote:
> 
> I've discovered org-outline-level which when in a code block under a given header delivers as expected:
> 
> * This old level
> #+BEGIN_SRC emacs-lisp
> (org-current-level)
> #+END_SRC
> 
> #+RESULTS:
> : 1
> 
> Now, how could I turn this into an interactive callable with M-x? My stab in the dark
> 
> (defun my-insert-level ()
>   (interactive)
>   (insert (org-outline-level)))

> doesn't seem to be working. 

It works, but just isn't what you wanted. ;-)

Note:

,----[ C-h f insert RET ]
| insert is a built-in function in ‘C source code’.
| 
| (insert &rest ARGS)
| 
| Insert the arguments, either strings or characters, at point.
| Point and after-insertion markers move forward to end up
|  after the inserted text.
| [...]
`-----


So try something like

(defun my-insert-level ()
  (interactive)
  (insert (format "%d" (org-outline-level))))

To insert a string.

HTH,

Chuck

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

end of thread, other threads:[~2019-12-30 18:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-12-30  5:26 Turn function into interactive Lawrence Bottorff
2019-12-30 18:43 ` Berry, Charles

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