The Org-mode cache option, see https://orgmode.org/manual/cache.html, saves a lot of time when exporting to html. Unfortunately I cannot get it working when passing var parameters.
This is how it looks like in Org:
#+tblname: howtocache
| x | y |
|---+---|
| 1 | 5 |
| 2 | 2 |
| 3 | 1 |
| 4 | 6 |
| 5 | 3 |
#+begin_src gnuplot :cache yes :var data=howtocache :exports code :file howtocache.png
reset
plot data u 1:2 w l
#+end_src
#+RESULTS[4a0d86e3196a769ad675be613318b8fb77d47f2e]:
[[file:howtocache.png]]
When I evaluate the gnuplot block I always get a new hash value.
In the gnuplot buffer I see the data is provided from a different temporary file.
One run:
data = "c:/Users/harald/AppData/Local/Temp/babel-14152bAf/gnuplot-141521-y"
Another run:
data = "c:/Users/harald/AppData/Local/Temp/babel-14152bAf/gnuplot-14152OnU"
Probably the hash is calculated based on the filename.
The main question is: How can I use cache together with var?
Found a reasonable solution on:
https://emacs.stackexchange.com/a/24126
Evaluate manually on change, not on export
Put :eval no-export in your header arguments, and the processing won't
happen on export, only when you manually call it with C-c C-c or
M-x org-babel-execute-buffer.
Thanks to your infomration about the changing temp file, I've found a general solution for gnuplot caching that works for both regular execution and exporting. Rather than passing data directly to the gnuplot src block and letting ob-gnuplot write a temp file, I write the temp file myself, cached it, and passed the file name to the gnuplot src block instead. This works because ob-gnuplot only writes files for vectors in its input, and we're bypassing that by giving it a string instead.
Here's some code to illustrate, based on the example above:
#+tblname: howtocache
| x | y |
|---+---|
| 1 | 5 |
| 2 | 2 |
| 3 | 1 |
| 4 | 6 |
| 5 | 3 |
#+name: data-file
#+begin_src elisp :cache yes :var data=howtocache
(org-babel-gnuplot-table-to-data data (org-babel-temp-file "gnuplot-") '())
#+end_src
#+RESULTS[25d02647c9b4a748ce6798d81e70d72c3ace0846]: data-file
: /var/folders/n4/vg52wwmn02xbfx_4g2l53z1m0000gn/T/babel-eiHU75/gnuplot-8osPqw
#+begin_src gnuplot :cache yes :var data=data-file :exports code :file howtocache.png
reset
plot data u 1:2 w l
#+end_src
#+RESULTS[af6331cf9eac29a503e86eb07dc76a1a0d808f85]:
[[file:howtocache.png]]
Hopefully this will be useful to future googlers of this thread, with the same use-case
Related
I want to display something in a specific emacs buffer. If the buffer is not already displayed in some window, I want to display it in a new window in the current frame. If it is already displayed somewhere, I do not want to bring this window or frame up or to focus. Things I have tried:
(pop-to-buffer buf nil 'norecord)
This does not work, since when I am in a different frame to the one that displays "buf", it will open a new window.
(display-buffer buf nil t)
This almost works, but it raises the frame showing the buffer. I wish the frame to remain in the background.
How to proceed? Maybe there is a function to check whether a buffer is already displayed in some frame in some window?
If I understood you question correctly the following function will do what you want
(defun my-switch-to-buffer (buffer)
(interactive
(list (ido-read-buffer "Switch to buffer: ")))
;; get-buffer-window (with second argument t) will return
;; nil if the buffer is not open in any window across any
;; frame
(unless (get-buffer-window buffer 0)
(pop-to-buffer buffer nil t)))
What Emacs version are you using? display-buffer was changed quite a bit in Emacs 24, offering an almost limitless number of display possibilities. But as a result the behavior is in general non-trivial, as is also the doc.
(And pop-to-buffer always selects the buffer, which you say you do not want.)
Here is the doc for display-buffer from a recent Emacs build. Consult the Elisp manual for even more info. Regardless of whether someone gives you a short answer here that is sufficient, you might well want to learn how to tame the display-buffer beast. (Good luck.)
,----
| display-buffer is an interactive compiled Lisp function in
| `window.el'.
|
| It is bound to C-x 4 C-o.
|
| (display-buffer BUFFER-OR-NAME &optional ACTION FRAME)
|
| Display BUFFER-OR-NAME in some window, without selecting it.
| BUFFER-OR-NAME must be a buffer or the name of an existing
| buffer. Return the window chosen for displaying BUFFER-OR-NAME,
| or nil if no such window is found.
|
| Optional argument ACTION, if non-nil, should specify a display
| action. Its form is described below.
|
| Optional argument FRAME, if non-nil, acts like an additional
| ALIST entry (reusable-frames . FRAME) to the action list of ACTION,
| specifying the frame(s) to search for a window that is already
| displaying the buffer. See `display-buffer-reuse-window'
|
| If ACTION is non-nil, it should have the form (FUNCTION . ALIST),
| where FUNCTION is either a function or a list of functions, and
| ALIST is an arbitrary association list (alist).
|
| Each such FUNCTION should accept two arguments: the buffer to
| display and an alist. Based on those arguments, it should
| display the buffer and return the window. If the caller is
| prepared to handle the case of not displaying the buffer
| and returning nil from `display-buffer' it should pass
| (allow-no-window . t) as an element of the ALIST.
|
| The `display-buffer' function builds a function list and an alist
| by combining the functions and alists specified in
| `display-buffer-overriding-action', `display-buffer-alist', the
| ACTION argument, `display-buffer-base-action', and
| `display-buffer-fallback-action' (in order). Then it calls each
| function in the combined function list in turn, passing the
| buffer as the first argument and the combined alist as the second
| argument, until one of the functions returns non-nil.
|
| If ACTION is nil, the function list and the alist are built using
| only the other variables mentioned above.
|
| Available action functions include:
| `display-buffer-same-window'
| `display-buffer-reuse-window'
| `display-buffer-pop-up-frame'
| `display-buffer-pop-up-window'
| `display-buffer-in-previous-window'
| `display-buffer-use-some-window'
|
| Recognized alist entries include:
|
| `inhibit-same-window' -- A non-nil value prevents the same
| window from being used for display.
|
| `inhibit-switch-frame' -- A non-nil value prevents any other
| frame from being raised or selected,
| even if the window is displayed there.
|
| `reusable-frames' -- Value specifies frame(s) to search for a
| window that already displays the buffer.
| See `display-buffer-reuse-window'.
|
| `pop-up-frame-parameters' -- Value specifies an alist of frame
| parameters to give a new frame, if
| one is created.
|
| `window-height' -- Value specifies either an integer (the number
| of lines of a new window), a floating point number (the
| fraction of a new window with respect to the height of the
| frame's root window) or a function to be called with one
| argument - a new window. The function is supposed to adjust
| the height of the window; its return value is ignored.
| Suitable functions are `shrink-window-if-larger-than-buffer'
| and `fit-window-to-buffer'.
|
| `window-width' -- Value specifies either an integer (the number
| of columns of a new window), a floating point number (the
| fraction of a new window with respect to the width of the
| frame's root window) or a function to be called with one
| argument - a new window. The function is supposed to adjust
| the width of the window; its return value is ignored.
|
| `allow-no-window' -- A non-nil value indicates readiness for the case
| of not displaying the buffer and FUNCTION can safely return
| a non-window value to suppress displaying.
|
| The ACTION argument to `display-buffer' can also have a non-nil
| and non-list value. This means to display the buffer in a window
| other than the selected one, even if it is already displayed in
| the selected window. If called interactively with a prefix
| argument, ACTION is t.
`----
You may try (source: http://www.chemie.fu-berlin.de/chemnet/use/info/emacs/emacs_19.html):
C-x b buffer RET
To select or create a buffer named buffer (switch-to-buffer).
C-x 4 b buffer RET
Similar, but select buffer in another window (switch-to-buffer-other-window).
C-x 5 b buffer RET
Similar, but select buffer in a separate frame (switch-to-buffer-other-frame).
Also interesting about multiple windows/frames: http://www.chemie.fu-berlin.de/chemnet/use/info/emacs/emacs_20.html#SEC157
I can't find my way around copying a column, or a series of them, from a table.
The only solution I found so far is to copy the whole table and then delete the columns I don't need.
I suppose there must be another easier way for this. Maybe I am just too tired to realize how to do it.
I think the easiest way would be to take advantage of emacs rectangles
To create your rectangle, put your cursor at one of the corners of the rectangle you want to create.
Use C-SPC, or whatever you have set-mark-command set to.
Place your cursor at the diagonal corner of your rectangle.
Use C-x r rr to copy the rectangle to the register named r
Use C-x r ir to insert the rectangle that is being held in the register named r.
Following this process will copy and insert the columns that you want. You may need to repeat this process if the columns are not adjacent.
NOTE
I am using a bolded r to denote that this is technically a name of the register, and not some special input.
If you specifically want to copy the column(s) into another org table (or indeed back into the original table), there's support for that.
See C-hf org-table-copy-region RET
It works much like the regular rectangle commands, so it's not a better interface for selecting the column; but the associated paste command is smart about what it does with the content.
I you are planning to use emacs rectangle command you avoid the use of registers by using the command copy-rectangle-as-kill bound C-xrM-w, execute the command after selecting a region this will copy the rectangle (see this for an example of how marking rectangles works). Then you can paste the copied retangle by doing C-xry.
UPDATE
The page org-mode hacks describes a way to copy columns using org-table formulas. You will need to name the table.
Here is an example of using table formulas to copy columns from another table
Suppose you have following table named FOO, it is necessary to name the table for referring it from table formulas.
#+TBLNAME: FOO
| 0 | 2 | 1 |
| 1 | 3 | 2 |
| 2 | 4 | 3 |
You want to copy the columns 1 and 3 from table FOO to column 1 and 3 of the following table (lets call it B)
| | 5 | |
| | 6 | |
| | 7 | |
The following formula will do the trick, you will need to copy the formula below the table B and move cursor on the formula and do C-cC-c
#+TBLFM: $1=remote(FOO,###$1)::$2=remote(FOO,###$3)
The table B will be converted to the following
| 0 | 5 | 1 |
| 1 | 6 | 2 |
| 2 | 7 | 3 |
You can read about the syntax of the org table formulas here, basically $N refers to Nth column, #N refers to Nth row. ## and $# can be used instead of N to refer the row and column where the current value goes. remote(table-name, #N$N) refers to the Nth row and Nth column of the table table-name. :: concats multiple formulas.
I too had trouble using the standard rectangle operations. When moving to the next column, all of all of the rows between the point and the mark were highlighted. When I tried copying columns by formula as described above and in the org mode hacks, org threw errors if the column's values were non-numeric with more than one word.
But a good hint about cutting and pasting revealed that the problem is the initial direction of motion of the cursor. Moving first rightward to the next column, then down highlights the correct region. Standard rectangle operations then work correctly.
The "native" way in org mode is already covered in the answer by user2053036; I just wanted to add that in the simpler context, "to copy a column within a table": Let's say you have this table
| hello | world |
| is | good |
And want to repeat column 2 in column 3.
Steps:
Place the cursor after the bottom right | of the table
Open a new column to the right using keys Alt-Shift-<right>
| hello | world | |
| is | good | |
Add the "row copy from" formula (for example by putting cursor to row 1 column 3 and typing =$1 C-c C-c; or just type the TBLFM below the table and jump to step 4)
| hello | world | hello |
| is | good | |
#+TBLFM: $3=$1
Place the cursor on the TBLFM and type C-c C-c
| hello | world | hello |
| is | good | is |
#+TBLFM: $3=$1
That will copy column 1 to column 3.
I would like to insert a ASCII art table (as below) in the documentation.
The Markdown feature of doxygen comes in the way and messes it all up.
I've tried to the HTML table and they are fine but the source document becomes unreadable then.
Can I somehow get doxygen not to process a section but still include it in the output file?
Similar to here where 4 blanks allow to to inserted already formatted text in fixed width font.
|-------------|-------------------------|---------------|
|AUTO_NEW_OFF | Entry action | LED_FLASH |
| | | SEQ_OFF |
|-------------|-------------------------|---------------|
| | eXit action | |
|-------------|-------------------------|---------------|
| | | |
|-------------|-------------------------|---------------|
| OFF | SEQ complete | |
|-------------|-------------------------|---------------|
I think I can answer this myself already.
The Fenced Code Blocks ( 3 x ~) feature seems to work ok
~~~
|-------------|-------------------------|---------------|
| MAN_NEW_OFF | Entry action | LED_FLASH |
| | | SEQ_OFF |
|-------------|-------------------------|---------------|
~~~
An improvement on fenced code would be to surround the table with the doxygen commands #verbatim and #endverbatim.
If you use a "code" style, be that markdown's ~~~ or doxygen's #code, there's a chance that current or future versions of Doxygen will start trying to colour it in syntactically.
I have an Emacs org mode table that looks like this:
|--------------------------------+------------------------------------------------------|
| <20> | <60> |
| How do you alter your password | The command to alter your password in oracle is:: |
| in Oracle? | |
| | ALTER USER {userid} IDENTIFIED BY {password}; |
| | |
|--------------------------------+------------------------------------------------------|
When the table is resized with C-c C-c i.e. with keyboard shortcut: Ctrl-C + Ctrl-C, or automatically, it ruins the spacing inside of the table elements and I get:
|--------------------------------+------------------------------------------------------|
| <20> | <60> |
| How do you alter your password | The command to alter your password in oracle is:: |
| in Oracle? | |
| | ALTER USER {userid} IDENTIFIED BY {password}; |
| | |
|--------------------------------+------------------------------------------------------|
It automatically trims the leading spaces from the content in the table. Is there a way to prevent this in org mode tables? I want org mode to not change the formatting of the content.
This is with Emacs version 24.3.50, but the behavior is the same in version 24.2 (I tried in both versions).
A really hack-ish way to work around it is to redefine or defadvice around org-table-align. The relevant snippet is roughly around here. By changing * to ?, you'll keep the spaces at the beginning.
--- ./org-table.el
+++ ./org-table.el.orig
## -752,7 +752,7 ##
;; Get the data fields by splitting the lines.
(setq fields (mapcar
(lambda (l)
- (org-split-string l " *| *"))
+ (org-split-string l " *| ?"))
(delq nil (copy-sequence lines))))
;; How many fields in the longest line?
(condition-case nil
I'm not sure if you really want to do that, though. Would you consider restructuring your markup, perhaps by using headings instead, with a custom markup function in case you really need it to look like tables afterwards? If that makes you boggle, another way to accomplish that might be with #+BEGIN_HTML and #+END_HTML blocks. Not elegant, but ah well...
I'm using ECB (Emacs Code Browser) and my default layout is as follows:
;; +------+-------+--------------------------------------+
;; | | |
;; | Directories | |
;; | | |
;; +------+-------+ |
;; | History | Edit |
;; +------+-------+ |
;; | Methods | |
;; | | |
;; +-----------------------------------------------------+
By default, the methods are presented in the order they appear in the edited buffer, yet I'm searching for a way of having them sorted by name. I wanted to use something like ecb-methods-sort-method but it does not seem to exist.
Any hint on how to set it up?
I took quick look at the docs, Look slike you can customize 'ecb-methods-menu-sorter'.
C-h v ecb-methods-menu-sorter
From the docs:
*Function which re-sorts the menu-entries of the directories buffer.
If a function then this function is called to re-arrange the menu-entries of
the combined menu-entries of the user-menu-extensions of
`ecb-directories-menu-user-extension' and the built-in-menu
`ecb-directories-menu'. If nil then no special sorting will be done and the
user-extensions are placed in front of the built-in-entries.
The function get one argument, a list of menu-entries. For the format of this
argument see `ecb-directories-menu-user-extension'. The function must return a
new list in the same format. Of course this function can not only re-arrange
the entries but also delete entries or add new entries.