I set the yasnippet of elisp src as
#+begin_src emacs-lisp :session `(current-buffer)` :lexical t
$0
#+end_src
Which set the current-buffer as session name
#+begin_src emacs-lisp :current-file-name sicp :lexical t
(current-buffer)
#+end_src
#+RESULTS:
: #<buffer yasnippet-offprint.org>
A minor problem is to remove suffix org from yasnippet-offprint.org.
This might be trivial, but search the elisp manual, thus did not got an immediate solution.
How could remove the suffix the yasnippet-offprint.org
The result I desire is
#+begin_src emacs-lisp :session yasnippet-offprint :lexical t
#+end_src
You can use file-name-sans-extension, e.g.,
(file-name-sans-extension "yasnippet-offprint.org")
;; => "yasnippet-offprint"
You can use C-h f (M-x describe-function) to read its docstring. And (info "(elisp) File Name Components") lists functions on manipulating filenames.
Related
I would like to count characters in a subtree (heading) in org mode. Right now I have figured out how to count characters in a single paragraph, but not over multiple paragraphs. I first define a source block:
#+NAME: countChars
#+BEGIN_SRC sh :var X="" :results output
echo "$X" | wc --chars
#+END_SRC
And then I use it on named paragraphs:
#+NAME: paragraph
This is the paragraph
#+CALL: countChars(paragraph)
This works well but the #+NAME: only covers one paragraph. I have tried to use a heading as argument but I could not make it work.
EDIT: Based on comments, I came up with:
#+NAME: countChars
#+BEGIN_SRC emacs-lisp :results output :eval no-export :exports results
(interactive)
(save-excursion
(org-mark-subtree)
(setq a (- (mark) (point)))
(deactivate-mark)
(prin1 'Count= )
(prin1 a))
#+END_SRC
which does almost what I want when invoked as
#+CALL: countChars()
but has the problem of counting source code blocks (including itself) as well as text. I would like to count text only (excluding the headline).
You can only use #+NAME in front of a source block, not a subtree.
It's easier to write this in emacs lisp.
This code block will count the number of characters in the current subtree, not including the header or the last line of the content:
If you want to count the number of characters in the current subtree using emacs lisp, try this:
(save-excursion
(org-mark-subtree) ;mark the whole subtre
(forward-line 1) ;move past header
(exchange-point-and-mark) ;swap point and mark (ends of region)
(forward-line -1) ;move backwards past the last line
(let ((nchars (- (point) (mark))))
(deactivate-mark) ;clear the region
(message "%d" nchars))))
Using org, I'd like to execute Lisp code which prints the value of a variable into a results block. E.g. I'm trying to print the value of org-babel-default-header-args.
I've tried this:
#+BEGIN_SRC elisp :exports both
(print 'org-babel-default-header-args)
#+END_SRC
#+BEGIN_SRC elisp :exports both
(org-babel-default-header-args)
#+END_SRC
#+BEGIN_SRC elisp :exports both
(symbol-value 'org-babel-default-header-args)
#+END_SRC
The closest thing I've gotten to work is this:
#+BEGIN_SRC elisp :exports both
(describe-variable 'org-babel-default-header-args)
#+END_SRC
But that prints out some extra text. I'd like to literally just print the value of the variable.
To print the value of a variable foo, use
(print foo)
without quoting it. Quote inhibits evaluation: that's exactly what you don't want to do here.
I have some link-abbreviations in org-mode like this:
(setq org-link-abbrev-alist
'(("dropboxpath" . "~/Dropbox")
("cloudpath" . "~/")
("imgpath" . "~/images")
("gitpath" . "~/git")
))
It works fine and as i am working on different systems and syncing my org-files the paths are different on every system. My problem is the following:
#+BEGIN_SRC plantuml :file gitpath:/test.png
<some plantumlstuff here>
#+END_SRC
This is not working, org-babel does not recognize the link abbreviation.
I also tried the following (where temp is a variable containing the path to the git-directory):
#+BEGIN_SRC plantuml :file (concat temp "/test.png")
This works in principle but gives me the following result:
#+RESULTS:
[[file:~/git/test.png]]
This does not meet my requirements though because i need gitpath in order to make it work over all my machines...
#+RESULTS:
[[gitpath:/test.png]]
Does anybody have a suitable solution to this problem?
You can simply refer to org-link-abbrev-alist. Since that variable is structured as an alist, you can use assoc. It returns the first element of the alist that matches the supplied key.
(concat
(car (assoc "gitpath" org-link-abbrev-alist))
"/test.png")
I can use the org-babel-tangle to tangle the current file. I was wondering if you could have org export tangle all the code blocks in the org file.
thanks
EA
This runs org-babel-tangle when exporting:
#+NAME: tangle-it
#+BEGIN_SRC emacs-lisp :exports none
(org-babel-tangle)
#+END_SRC
#+BEGIN_SRC text :results silent :noweb yes :exports results
<<tangle-it()>>
#+END_SRC
#+BEGIN_SRC css :tangle test.css
body {
font-size: 12px;
}
#+END_SRC
It doesn't work when using it with #+CALL: tangle-it().
It is also possible to do this with a macro:
#+MACRO: tangle-it (eval (progn (org-babel-tangle) ""))
{{{tangle-it()}}}
#+BEGIN_SRC css :tangle test.css
body {
font-size: 12px;
}
#+END_SRC
I do this to export my elisp source blocks to specific files
#+BEGIN_SRC emacs-lisp :tangle lisp-file.el
(message "Hello lisp-file")
#+END_SRC
I think you can also set this as a property, so you could set properties at the node/tree level.
I would do it like this:
* build :noexport:
#+BEGIN_SRC emacs-lisp
(org-babel-tangle)
(org-latex-export-as-latex)
#+END_SRC
Then just type C-c C-c in the code block to tangle, then export. You can change the export command to whatever you want for other export types.
When passing arguments to code block that exports results Org-mode fails to export with the error "Wrong type argument: listp". How can I fix this?
Here is an example. When it is exported it gives the error 'Wrong type argument: listp, "bar"'.
#+TITLE: Example
#+SOURCE: example-one
#+BEGIN_SRC emacs-lisp :exports results
(setq foo "bar")
#+END_SRC
#+SOURCE: example-two
#+BEGIN_SRC emacs-lisp :exports results :var x=example-one
(setq foo (concat x x))
#+END_SRC
I am running Org-mode 7.6 in Emacs 23.3.1.
This issue might simply be with the older copy of Org that you're running. Tested it today with a recent git pull and get the results below. As pmr suggested, you might have better luck asking on the mailing list ( emacs-orgmode#gnu.org ) since there might be someone there who would know what caused this issue and what might have been changed to resolve it in later versions.
The features and examples discussed in the manual are based on the current release version (7.8.03 in this case) so they will not always be compatible with older versions. Does the info-node in your version indicate that it should work?
These 2 commands will show you the associated info-nodes for that section of the Org Manual
; The node itself
(Info-goto-node "(org) var")
; Parent node, in case the first node isn't present
(Info-goto-node "(org) Working With Source Code")
Test Results
Org
* Test variable passing
Headlines are created to split the code blocks apart. When trying to eval on export I'm getting a syntax read error which was reported here: http://lists.gnu.org/archive/html/emacs-orgmode/2012-01/msg00993.html
** Ex 1
#+name: example-one
#+BEGIN_SRC emacs-lisp :exports results
(setq foo "bar")
#+END_SRC
** Ex 2
#+name: example-two
#+BEGIN_SRC emacs-lisp :exports results :var x=example-one
(setq foo (concat x x))
#+END_SRC
Latex
\vspace*{1cm}
Headlines are created to split the code blocks apart. When trying to eval on export I'm getting a syntax read error which was reported here: \href{http://lists.gnu.org/archive/html/emacs-orgmode/2012-01/msg00993.html}{http://lists.gnu.org/archive/html/emacs-orgmode/2012-01/msg00993.html}
\section{Ex 1}
\label{sec-1}
\begin{verbatim}
bar
\end{verbatim}
\section{Ex 2}
\label{sec-2}
\begin{verbatim}
barbar
\end{verbatim}
in your .emacs file - make sure you have the following line:
(setq org-babel-load-languages
(quote ((emacs-lisp . t))))