org mode - clickable text jump to specific line in emacs - emacs

I have a file list and wish to jump to specific line if click the text.
#+BEGIN_SRC python :results output
for i in range(0,10):
print "[[./test%d.txt:100]]"%i
#+END_SRC
#+RESULTS:
#+begin_example
[[./test0.txt:100]]
[[./test1.txt:100]]
[[./test2.txt:100]]
[[./test3.txt:100]]
[[./test4.txt:100]]
[[./test5.txt:100]]
[[./test6.txt:100]]
[[./test7.txt:100]]
[[./test8.txt:100]]
[[./test9.txt:100]]
#+end_example
If without the linenumber at the end, click the text line will open the file but not jump to the specific line number.
How should I change the syntax to jump to line number?

In your example, the only problem was the syntax for Org external links. It is
[[./test%d.txt::100]] (and not [[./test%d.txt:100]])
This will work in your Emacs Org buffer, however the link will not be exported if you publish your file (C-c C-e h o).
If you also want to export/publish your links you can use:
#+OPTIONS: d:t \n:t
#+BEGIN_SRC python :results output drawer :exports both
for i in range(0,10):
print "[[./test%d.txt::100][test%d.txt::100]]" %(i,i)
#+END_SRC
The d:t option tells to export drawers, the \n:t one to preserve linebreaks.
Putting your python code result into a drawer (the :results output drawer) allows org mode to interpret it as true org-mode code.

Related

Org-mode: overwriting globals #+PROPERTIES: in block headers?

It is often the case that I want to have :results silent for all the code blocks in an Org-mode document. Do simplify my block headers, I define this in my Org-mode document:
#+PROPERTY: header-args :results silent
That works properly: all the codeblocks uses the :results silent option in the blocks' header.
However, if I specify :results output in one of the code block, it will still be silent. I would have expected that it would overwrite the global setting, but it doesn't seem so.
Am I right by saying that or is there something I am missing to get this behavior?
Here is an example of what I would like to do:
#+PROPERTY: header-args :results silent
...
#+BEGIN_SRC clojure
;; this one is silent
(def foo "bar)
#+END_SRC
...
#+BEGIN_SRC clojure :results output
;; this one is being outputted
(def foo "bar)
#+END_SRC
This seems to be a bug, present even in the most up-to-date version of org-mode. I've reported it on the org-mode mailing list.
EDIT: Charles Berry pointed out on the ML that this is not a bug. The opposite of "silent" is "replace", so the second source block should read:
#+BEGIN_SRC elisp :results output replace
;; this one is being outputted
(princ "foo")
#+END_SRC
See http://thread.gmane.org/gmane.emacs.orgmode/108001/focus=108008
and the :results section in the manual http://orgmode.org/org.html#results
Note that you get to pick one value for every section (collection, type, format, handling) - if you don't pick a value for a section, a default value is picked. In the above, there was no explicit value for "handling", so the default value from the property still controlled.

Emacs org does not evaluate source blocks at export anymore (version 8.3.2)

I have org-mode on two computers. On one, the version is 8.2.5h; one the other, 8.3.2.
Evaluation of source blocks works on the machine with the 8.2.5h version but not on the 8.3.2 version.
Here is a minimal example:
* Emacs org / R / latex.
Make a random number.
#+BEGIN_SRC R :session *R*
x <- rbeta(1000,10,10)
#+END_SRC
Plot the whole thing.
#+BEGIN_SRC R :session *R* :exports none
pdf(file="fig1.pdf", width=8, height=6)
hist(x, main="")
dev.off()
#+END_SRC
Now put it in this text file.
#+BEGIN_SRC latex
\begin{figure}[h!]
\centering
\includegraphics[width=.9\textwidth]{fig1.pdf}
\caption{Gamma distribution}
\label{fig:hist-gamma}
\end{figure}
#+END_SRC
Now a latex equation:
#+BEGIN_SRC latex
\begin{equation}
\label{eq:eq1}
y_{it} = \beta_0 + \beta_1 X_{it} + \varepsilon_{it}
\end{equation}
#+END_SRC
When I export this to latex with org mode version 8.2.5h, I get a pdf with the figure, the latex equation etc. When I export the same file to latex with org mode version 8.3.2, the source blocks are not evaluated; only the code for the first source block is shown.
I played with changing switches, none of these works. Is this a bug?
The problem was the variable org-export-babel-evaluate. For some reason that was set to nil. Apparently not an org-version problem but the description states "This variable was introduced, or its default value was changed, in version 24.1 of Emacs", so maybe that was the issue.

Have basic autoindentation in code blocks in org-mode

Emacs' fine org-mode has CODE and EXAMPLE blocks that are easily edited in a proper major mode using C-c '. But for quick alterations and minor edits one might prefer editing the block inline without opening new popup windows for a two-second operations.
Of course org lets you do that but the automatic indentations are off radar while editing inline like that. Where and what should I hack to make org's indentation logic to act like default dumb autoindentation (ie. copy the indent level of the previous line) while the cursor is in a code block?
#+BEGIN_SRC python
def foo():
return 42
#+END_SRC
#+BEGIN_EXAMPLE
Oh my
hh
#+END_EXAMPLE
If the cursor was at the end of the line containing hh, pressing C-j would get me a new line with the same indentation as the previous one.
The following allows me to edit (and indent) code "inline" without ever going to the indirect buffers (except for M-q on comments, which did work and does not anymore).
;; same effect for `tab' as in the language major mode buffer
(setq org-src-tab-acts-natively t)

Literate Programming using org-babel

I am on a literate program using org-babel. My source is structured like so,
-imports
-utility fns
-game structure
- detailed explanations
This is the normal structure of the code, what I would like to do is move explanations of the utility fns to the end so it does not show up first in the generated pdf file. Now this can be done with noweb extension, but the problem is when you have lots of little functions for each one I have to add a src_block with a unique name scroll down the file and add a reference to that in the file which is really annoying. Is there a way to name all the src_blocks in a section? say all code in this section goes into block A.
You can give multiple chunks the same name. For example, I generate my .emacs file with org-tangle, and at the top of the org file, I have a master template that looks something like this:
#+begin_src emacs-lisp :tangle "/path/to/.emacs" :comments both :noweb tangle
<<generated-file-warning>
<<includes>>
<<definitions>>
<<settings>>
<<generated-file-warning>
#+end_src
Underneath that, I have my outline with source blocks like so:
* extensions
** yasnippet
#+name: early-includes
#+begin_src emacs-lisp
(require 'yasnippet)
(yas/initialize)
#+end_src
#+name: settings
#+begin_src emacs-lisp
(yas/load/directory "/path/to/my/snippets")
#+end_src
Note: for older versions of org-mode, you may need to use #+srcname: instead of #+name:
You can also create a property called noweb-ref, which applies the same name to all source blocks in a sub-tree.

Hide latex (auctex) output buffer

When I compile a (Xe)LaTeX file, emacs writes the output to the LaTeX output buffer and shows it. For pure LaTeX, this buffer is hidden.
How do I hide a Latex compilation buffer?
Forget it, there is this (setq TeX-show-compilation t) in the script I was using, so I just set it to nil.