How to use default org-mode spreadsheet auto-sum behavior ? - emacs

In this example:
| | num |
|---+-----|
| | 5 |
| | 6 |
| | 4 |
|---+-----|
| # | 15 |
| ^ | sum |
#+TBLFM: $sum=vsum(#2..#-1);
Every time you press "tab" in the sum area or C-c C-c in the table formula area below the table it recalculates the sum area. The problem is after it recalculates this area it adds this new sum to the current sum that's already in the area. (Try it in your emacs).
I've created this basic test to show issues I've encountered in creating complex spreadsheets in org. Until I find a solution I can't trust the sums emacs gives me because I may occasionally press C-c C-c twice and it's inconvenient to have to go and zeo out all sum values in my form every time I recalculate.
If anyone knows a solution, please let me know.

Turns out it was a bug with the Org-mode version I was using:
release 5.23a is from Apr 23 10:17:27 2008
Kudos to Thumper_ in freenode #org-mode for pointing it out.
Be sure to update to the newest version of Org-mode, folks! :)

Maybe it's more clear to use vsum(#I..#II) to indicate the rows between the 2 hlines.
I cannot reproduce your accumulation problem; and just read your answer about the bug!!

Related

VSCode regex find and select data from specific group (not replace)

Consider the following dataset:
<uses-configuration
android:reqFiveWayNav=["true" | "false"]
android:reqHardKeyboard=["true" | "false"]
android:reqKeyboardType=["undefined" | "nokeys" | "qwerty" | "twelvekey"]
android:reqNavigation=["undefined" | "nonav" | "dpad" | "trackball" | "wheel"]
android:reqTouchScreen=["undefined" | "notouch" | "stylus" | "finger"] />
I am trying to select all the values after android:
In order to do this, i am using (a\w+:)(\w+) which does exactly what i want. I know that I can use the search and replace and use$2 to select the second group, but I dont want to replace anythin. I want to select anything the second group matches with alt+enter key press.
Is this possible?
What you really need is a lookaround. I don't believe that vscode supports lookbehinds (see issues: lookbehind support coming). But it does support lookaheads so :
(\w+)(?=\=\[.*\])
should work for you as long as your desired values are followed by "[.*]" and nothing undesired has that pattern. The lookahead part will not be selected by vscode. And then Alt-Enter selects all the matches.
If lookbehind was supported, maybe soon, this would work:
\b(?<=a\w+:)(\w+)\b
Just a note that indeed lookbehinds were implemented in vscode since the question and answer so the lookbehind solution \b(?<=a\w+:)(\w+)\b does work now.

Formatting tables in Swift documentation comments

I have a section of code like this sitting above my computed property:
/**
Data Types Conversions:
-----------------------
+-----------------+-------------+
| kernel | Swift/Obj-c |
+=================+=============+
| sampler | CISampler |
| __table sampler | CISampler |
| __color | CIColor |
| float | NSNumber |
| vec2/3/4 | CIVector |
+-----------------+-------------+
*/
When it is rendered in the formatted comments pop-up I see garbled text.
Is there a way to represent this data in a table that actually renders when you option-click on the associated computed property?
I solved this problem with a code indent.
I don't know of any code markup for tabular formatting like that. I suggest you check Apple's site on their code documentation format:
https://developer.apple.com/library/content/documentation/Xcode/Reference/xcode_markup_formatting_ref/Throws.html#//apple_ref/doc/uid/TP40016497-CH26-SW1
You can also do this without indenting by using a "fenced" code block, surrounding your table (or code block) by triple backticks (```), the same way it works on stack overflow. But indenting may be cleaner and save vertical space.

How to select a column of a table in emacs org mode

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.

Orgmode Table Formatting of Cells

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

How to use Emacs auto-complete/snippets?

I've been using the emacs-live and it is amazing!
I just can't figure out how to use the autocomplete/snippets, the suggestions pop up, you can cycle through the options, but how do you select an option.
I've tried numinous things to get it to apply the selection, nothing seems to work, it's driving me crazy.
Can someone please help me?
I seem to have fixed the problem by pulling the latest version of the config. Not sure what I changed or was changed but it is working now.
Digging around I found a manual for the plugin with this:
### Summary ###
Completion will be started by inserting characters. After completion is started,
operations in the following table will be enabled temporarily. After completion
is finished, these operations will be disabled.
| Key | Command | Description |
|-----------|-------------|---------------------------|
| TAB, C-i | ac-expand | Completion by TAB |
| RET, C-m | ac-complete | Completion by RET |
| down, M-n | ac-next | Select next candidate |
| up, M-p | ac-previous | Select previous candidate |
| C-?, f1 | ac-help | Show buffer help |
To stop completion, simply use `C-g`.