* Emacs speaks to spreadsheet
@ 2014-08-27 12:51 Tak Kunihiro
0 siblings, 0 replies; only message in thread
From: Tak Kunihiro @ 2014-08-27 12:51 UTC (permalink / raw)
To: emacs-orgmode; +Cc: tkk
To make a plot using org-babel/R with org-table (as data.frame) is an
ultimate weapon for me. Thank you for development.
Occasionally I want to transport datasets between Excel and org-table.
Two essential operations are (a) to copy cells from Excel and paste
into org-table and (b) other way around. How those would work is
describe as below.
(a) Copy cells from Excel and paste into org-table
- Datasets copied at Excel are stored in kill-ring as tabulated text.
Tabulated text would be converted into org-table-clip.
- A user selects a cell in org-table and pastes the datasets by
(org-table-paste-rectangle)
(b) Copy cells from org-table and paste into Excel
- A user selects cells by mouse drag on org-table and copies datasets
by (org-table-copy-region).
- The datasets are store as org-table-clip. They would be converted
into tabulated text and stored in kill-ring.
- A user will paste the datasets in Excel
When those are assigned to (a) M-s-v and (b) M-s-c, Emacs speaks to
spreadsheet nicer than I expected. I want to let you know!
Followings barely work.
--
(global-set-key (kbd "M-s-x") 'orgtbl-cell-cut)
(global-set-key (kbd "M-s-c") 'orgtbl-cell-copy)
(global-set-key (kbd "M-s-v") 'orgtbl-cell-paste)
(defun orgtbl-cell-copy ()
"Copy cells in org-table and store as tabulated text in
kill-ring."
(interactive)
(if (org-at-table-p)
(progn (call-interactively 'org-table-copy-region)
(clip-orgtbl2tab)
(exchange-point-and-mark))
(call-interactively 'copy-rectangle-as-kill)
(clip-rectangle2text)))
(defun orgtbl-cell-cut ()
"Cut cells in org-table and store as tabulated text in
kill-ring."
(interactive)
(if (org-at-table-p)
(progn (call-interactively 'org-table-cut-region)
(clip-orgtbl2tab))
(call-interactively 'kill-rectangle)
(clip-rectangle2text)))
(defun orgtbl-cell-paste (&optional arg)
"Paste tabulated text stored in kill-ring into org-table. If point is not on org-table,
this creates a new org-table."
(interactive "P")
(cond
(arg
(org-table-paste-rectangle))
((org-at-table-p) ; (org-table-check-inside-data-field t)
(clip-tab2orgtbl)
(org-table-paste-rectangle))
(t
(let (tempclip-in-orgtbl)
(with-temp-buffer
(org-table-create "1x1")
(goto-char (+ 1 (point)))
(clip-tab2orgtbl)
(org-table-paste-rectangle)
(mark-whole-buffer)
(setq tempclip-in-orgtbl (buffer-substring (point-min) (point-max))))
(insert tempclip-in-orgtbl)))))
(defun clip-tab2orgtbl ()
"Create org-table-clip from tabulated text stored in
kill-ring."
(with-temp-buffer
(org-mode)
(yank)
(orochi-tbl-tab2org (point-min) (point-max))
(goto-char (+ 1 (point-min)))
(org-table-align)
(org-table-copy-region (+ 1 (point-min)) (- (point-max) 2))))
(defun clip-orgtbl2tab ()
"Store tabulated text to kill-ring that was converted from
org-table-clip."
(with-temp-buffer
(org-mode)
(org-table-create "1x1")
(goto-char (+ 1 (point-min)))
(org-table-paste-rectangle)
(mark-whole-buffer)
(call-interactively 'orochi-tbl-org2tab)
(mark-whole-buffer)
(call-interactively 'kill-region)))
(defun clip-rectangle2text ()
"Convert killed-rectangle to normal text and store in
kill-ring."
(with-temp-buffer
(yank-rectangle)
(mark-whole-buffer)
(call-interactively 'kill-region)))
(defun orochi-tbl-org2tab (start end)
"Convert orgtbl on region to tab delimited text"
(interactive "r")
(orochi-replace-regexps '(("^\s*\|\-.*\n" . "")
("^\s*\|\s*" . "")
("\s*\|\s*$" . "")
("\s*\|\s*" . " "))
start end))
(defun orochi-replace-regexps (rep-list start end)
"Find and replace region for a set of regexps"
(save-excursion
(save-restriction
(narrow-to-region start end)
(dolist (re-rep rep-list)
(goto-char (point-min))
(while (re-search-forward (car re-rep) nil t)
(replace-match (cdr re-rep)))))))
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2014-08-27 12:51 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-27 12:51 Emacs speaks to spreadsheet Tak Kunihiro
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).