* Re: (noob) interactive template? how?
2014-11-05 20:06 ` Sven Ehret
@ 2014-11-05 22:03 ` Brady Trainor
0 siblings, 0 replies; 4+ messages in thread
From: Brady Trainor @ 2014-11-05 22:03 UTC (permalink / raw)
To: Sven Ehret; +Cc: emacs-orgmode
Sven Ehret <sven@ehlu.name> writes:
> Thank you a hundred times for your friendly and helpful response to
> message that was so brief that I admittedly consider it unreasonable demand.
>
Glad I could help! I am so new to, so it is an opportunity.
> I am a noob to Emacs and to Org-mode, and I do not know how to execute
> the emacs-lisp yet, but I have yanked the code into ~/.emacs. Now, the
> real key to my question was the part about pressing M-x. That I was not
> able to figure out. From the code I assumed that it was looking for a
> Recipe section, but all the other templates I came across worked with
> the C-c capture method.
>
SHORT VERSION:
To use M-x, it is really:
Hold down Alt key, tap x, release Alt key, type recipe-template, and tap return.
Altogether, I would just write something like "M-x recipe-template RET".
To execute emacs-lisp in an Emacs buffer, put cursor after closing parantheses and type "C-x C-e". That's
Hold down Control key, tap x, tap e, then release Control key.
So you could try executing
#+BEGIN_SRC emacs-lisp
(print "hello")
#+END_SRC
in this way.
LONG VERSION:
Yes, the capture templates are part of Org-mode, so let's zoom out to Emacs, and Emacs-lisp.
_Intro to M-x_
For instance, when you yanked the text into your ~/.emacs, you could have done so with =C-y=. The conventional Emacs notation there translates to =Ctrl+y=, that is, hold down =control=, tap =y=, and release =control=.
So, for the very used =M-x=, this means =Alt+x=, that is, hold down the =alt= key, tap =x=, and release the =alt= key. (On my keyboard, I do this with thumb and middle-finger.)
But why does =M= correspond with =Alt=?!?! Well the history of Emacs goes back to the days of different keyboards. The =Alt= key used to be the =Meta= key. So the Emacs community still writes things like =M-x= and =M-:= (=Alt+Shift+;=).
So you can try =M-: M-( print "hello" RET=.
Also try =M-x yank RET= (hopefully your last item on your clipboard (or kill-ring) isn't huge). =C-y= is a shortcut for that last command, but what doesn't have a key command, we might still access commands from the =M-x= minibuffer interaction.
Note that =M-x= can only execute commands, and not functions. To be more precise, commands are a special case of functions where the line =(interactive)= is included, in other words, commands are interactive functions, and so can be called by user from the =M-x= minibuffer, or with keybindings.
_Intro to Emacs_
Recently I was accessing a server remotely, and realized the commands I missed most were cut copy and paste. (I fixed that.) So maybe being new to Emacs is a lot like being new to accessing a server remotely.
Then here are some key commands you might want to know:
,----
| C-w - cut
| M-w - copy
| C-y - paste
`----
(Unless you have cua-mode enabled somehow, in which case it is the more modern set, C-x, C-c, C-v, when text is selected.)
How to select text? With mouse, or via C-SPC to set mark, and move point to select region. C-SPC again to unset mark.
To navigate within your file, you can probably just use your cursor keys until you have time to learn other shortcuts.
But to navigate between files, you'll probably want to know:
,----
| C-x C-f - find-file
| C-x d - dired
| C-x b - switch-buffer
`----
Those are the basics. But they may be available via mouse if your menu bar and toolbar are visible. (=M-x menu-bar-mode RET= and =M-x tool-bar-mode RET=.)
_Intro to Emacs-lisp_
If you have some Emacs-lisp in an Emacs buffer, such as
#+BEGIN_SRC emacs-lisp
(print "hello")
#+END_SRC
You can put cursor after the closing parantheses and type =C-x C-e= to execute the expression.
We might as well consider a key-binding for your recipe template, something like
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "C-c r") 'recipe-template)
#+END_SRC
So with this key-binding, you can now type =C-c r= to start a recipe template.
We could even spice it up to work from anywhere,
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "C-c r")
'(lambda ()
(interactive)
(find-file "~/food.org")
(recipe-template)))
#+END_SRC
No guarantees it will work. You might want to take the idea of the author and try to create an org capture-template, or modify the author's code to work from anywhere (or did it already, I forgot). I was just skimming through the Introduction to Emacs Lisp info, and they mention how useful =save-excursion= is. (https://www.gnu.org/software/emacs/manual/html_node/eintr/save_002dexcursion.html). That might be relevant here, not sure.
The possibilities are endless with Emacs. I try to mix in working with good enough solutions and getting stuff done into my undying exploration of Emacs and Org-mode configuring. I think of it as a Bonsai tree.
HTH
--
Brady
> Thanks to you, I was able to introduce an Org file to my recipe project
> and I am happy to have another use case for Org.
>
> Cheers! Sven.
>
> Am 04.11.2014 um 00:21 schrieb Brady Trainor:
>> Sven Ehret <sven@ehlu.name> writes:
>>
>>> Hello,
>>>
>>> sorry for my noob question. I searched the list but cannot find anything
>>> that would fit.
>>>
>> It's not clear how noob you are? To Emacs? To Org-mode?
>>
>> Do you know how to execute the emacs-lisp? Or otherwise insert into
>> your init file?
>>
>> Do you know that these functions are commands because of the
>> "(interactive)" lines, so can be called with M-x? Do you know the
>> M-x ALT+x deal?
>>
>> The functions look for a headline "* Recipe", so your org buffer
>> should have that first. M-x recipe-template will prompt for Titel
>> due to "read-string" (I type "M-x describe-function" with cursor on
>> "read-string" to read the documentation, or the more brief "C-h f").
>>
>> The command "food/gen-shopping-list" seems to look for an entry "*
>> Einkaufsliste", and headlines with "TOCOOK" state, but I did not
>> succeed in getting the command to work. Perhaps I should have had
>> some tabular data like can be found at
>> http://sachachua.com/blog/2012/06/emacs-org-grocery-lists-batch-cooking/.
>>
>> Hope this helps reshape your question at least.
>>
>>> My question is: How would I use the template(s) on
>>> http://lebensverrueckt.haktar.org/articles/org-mode-Food/ ?
>>>
>>> Thank you for your attention!
>>>
>>> Best, Sven.
^ permalink raw reply [flat|nested] 4+ messages in thread