all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* paste from clip to code block
@ 2015-04-17  7:21 Xebar Saram
  2015-04-17 13:56 ` John Kitchin
  0 siblings, 1 reply; 10+ messages in thread
From: Xebar Saram @ 2015-04-17  7:21 UTC (permalink / raw)
  To: org mode

[-- Attachment #1: Type: text/plain, Size: 173 bytes --]

Hi all

i was wondering if anyone has every created a function to auto paste what
in the sysclip/emas clip into org but as a formatted code block?
any clue anyone?

best

Z

[-- Attachment #2: Type: text/html, Size: 277 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: paste from clip to code block
  2015-04-17  7:21 paste from clip to code block Xebar Saram
@ 2015-04-17 13:56 ` John Kitchin
  2015-04-17 14:36   ` Xebar Saram
  2015-04-17 15:08   ` Jorge A. Alfaro-Murillo
  0 siblings, 2 replies; 10+ messages in thread
From: John Kitchin @ 2015-04-17 13:56 UTC (permalink / raw)
  To: Xebar Saram; +Cc: org mode

I like this kind of keyboard shortcut:

For python:
<p TAB C-w

For emacs-lisp

<el TAB C-w

What else would you want?

If you like yasnippets, you could do this:

# -*- mode: snippet; require-final-newline: nil -*-
# --

#+begin_src python
`(yank)`
#+end_src

$0

Or some kind of lisp function like:
#+BEGIN_SRC emacs-lisp
(defun paste-python-code ()
  (interactive)
  (insert "#+BEGIN_SRC python\n")
  (yank)
  (insert "\n#+END_SRC"))
#+END_SRC

I guess you need one of these for every language type.
Xebar Saram writes:

> Hi all
>
> i was wondering if anyone has every created a function to auto paste what
> in the sysclip/emas clip into org but as a formatted code block?
> any clue anyone?
>
> best
>
> Z

--
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: paste from clip to code block
  2015-04-17 13:56 ` John Kitchin
@ 2015-04-17 14:36   ` Xebar Saram
  2015-04-17 15:08   ` Jorge A. Alfaro-Murillo
  1 sibling, 0 replies; 10+ messages in thread
From: Xebar Saram @ 2015-04-17 14:36 UTC (permalink / raw)
  To: John Kitchin; +Cc: org mode

[-- Attachment #1: Type: text/plain, Size: 1119 bytes --]

thx john

that are very helpful tips!

Z

On Fri, Apr 17, 2015 at 4:56 PM, John Kitchin <jkitchin@andrew.cmu.edu>
wrote:

> I like this kind of keyboard shortcut:
>
> For python:
> <p TAB C-w
>
> For emacs-lisp
>
> <el TAB C-w
>
> What else would you want?
>
> If you like yasnippets, you could do this:
>
> # -*- mode: snippet; require-final-newline: nil -*-
> # --
>
> #+begin_src python
> `(yank)`
> #+end_src
>
> $0
>
> Or some kind of lisp function like:
> #+BEGIN_SRC emacs-lisp
> (defun paste-python-code ()
>   (interactive)
>   (insert "#+BEGIN_SRC python\n")
>   (yank)
>   (insert "\n#+END_SRC"))
> #+END_SRC
>
> I guess you need one of these for every language type.
> Xebar Saram writes:
>
> > Hi all
> >
> > i was wondering if anyone has every created a function to auto paste what
> > in the sysclip/emas clip into org but as a formatted code block?
> > any clue anyone?
> >
> > best
> >
> > Z
>
> --
> Professor John Kitchin
> Doherty Hall A207F
> Department of Chemical Engineering
> Carnegie Mellon University
> Pittsburgh, PA 15213
> 412-268-7803
> @johnkitchin
> http://kitchingroup.cheme.cmu.edu
>

[-- Attachment #2: Type: text/html, Size: 1840 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: paste from clip to code block
  2015-04-17 13:56 ` John Kitchin
  2015-04-17 14:36   ` Xebar Saram
@ 2015-04-17 15:08   ` Jorge A. Alfaro-Murillo
  2015-04-17 15:17     ` John Kitchin
  1 sibling, 1 reply; 10+ messages in thread
From: Jorge A. Alfaro-Murillo @ 2015-04-17 15:08 UTC (permalink / raw)
  To: emacs-orgmode

John Kitchin writes:

> I like this kind of keyboard shortcut: 
> 
> For python: <p TAB C-w 
> 
> For emacs-lisp 
> 
> <el TAB C-w 
>

I agree, this is the best method. Although probably you mean C-y 
instead of C-w.

For the record, this requires you to set up 
`org-structure-template-alist' to include python and emacs-lisp. 
For example, I use p and E, for python and emacs-lisp, so in my 
.emacs I have:

#+BEGIN_SRC emacs-lisp
  (eval-after-load "org"
         '(progn
            (add-to-list 'org-structure-template-alist
                         '("E"
                           "#+BEGIN_SRC emacs-lisp\n?\n#+END_SRC"
                           "<src 
                           lang=\\"emacs-lisp\\">\n\n?</src>"))
            (add-to-list 'org-structure-template-alist
                         '("p"
                           "#+BEGIN_SRC python\n?\n#+END_SRC"
                           "<src 
                           lang=\\"python\\">\n\n?</src>"))))
#+END_SRC
 
I even use the method in message-mode, for writing emails with 
code, like I just did now =)

Best,
 
-- 
Jorge.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: paste from clip to code block
  2015-04-17 15:08   ` Jorge A. Alfaro-Murillo
@ 2015-04-17 15:17     ` John Kitchin
  2015-05-07  7:59       ` Sebastien Vauban
  0 siblings, 1 reply; 10+ messages in thread
From: John Kitchin @ 2015-04-17 15:17 UTC (permalink / raw)
  To: Jorge A. Alfaro-Murillo; +Cc: emacs-orgmode@gnu.org

[-- Attachment #1: Type: text/plain, Size: 2406 bytes --]

you are right, I meant C-y ;)

I have these templates defined in my setup:

;; * Expansions for blocks
;; add <p for python expansion
(add-to-list 'org-structure-template-alist
             '("p" "#+BEGIN_SRC python\n?\n#+END_SRC" "<src
lang=\"python\">\n?\n</src>"))

;; add <por for python expansion with raw output
(add-to-list 'org-structure-template-alist
             '("por" "#+BEGIN_SRC python :results output raw\n?\n#+END_SRC"
"<src lang=\"python\">\n?\n</src>"))

;; add <pv for python expansion with value
(add-to-list 'org-structure-template-alist
             '("pv" "#+BEGIN_SRC python :results value\n?\n#+END_SRC" "<src
lang=\"python\">\n?\n</src>"))

;; add <el for emacs-lisp expansion
(add-to-list 'org-structure-template-alist
             '("el" "#+BEGIN_SRC emacs-lisp\n?\n#+END_SRC" "<src
lang=\"emacs-lisp\">\n?\n</src>"))

;; add <sh for shell
(add-to-list 'org-structure-template-alist
             '("sh" "#+BEGIN_SRC sh\n?\n#+END_SRC" "<src
lang=\"shell\">\n?\n</src>"))

John

-----------------------------------
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu


On Fri, Apr 17, 2015 at 11:08 AM, Jorge A. Alfaro-Murillo <
jorge.alfaro-murillo@yale.edu> wrote:

> John Kitchin writes:
>
>  I like this kind of keyboard shortcut:
>> For python: <p TAB C-w
>> For emacs-lisp
>> <el TAB C-w
>>
>
> I agree, this is the best method. Although probably you mean C-y instead
> of C-w.
>
> For the record, this requires you to set up `org-structure-template-alist'
> to include python and emacs-lisp. For example, I use p and E, for python
> and emacs-lisp, so in my .emacs I have:
>
> #+BEGIN_SRC emacs-lisp
>  (eval-after-load "org"
>         '(progn
>            (add-to-list 'org-structure-template-alist
>                         '("E"
>                           "#+BEGIN_SRC emacs-lisp\n?\n#+END_SRC"
>                           "<src
>  lang=\\"emacs-lisp\\">\n\n?</src>"))
>            (add-to-list 'org-structure-template-alist
>                         '("p"
>                           "#+BEGIN_SRC python\n?\n#+END_SRC"
>                           "<src
>  lang=\\"python\\">\n\n?</src>"))))
> #+END_SRC
>
> I even use the method in message-mode, for writing emails with code, like
> I just did now =)
>
> Best,
>
> --
> Jorge.
>
>
>

[-- Attachment #2: Type: text/html, Size: 4139 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: paste from clip to code block
  2015-04-17 15:17     ` John Kitchin
@ 2015-05-07  7:59       ` Sebastien Vauban
  2015-09-05 20:15         ` Grant Rettke
  0 siblings, 1 reply; 10+ messages in thread
From: Sebastien Vauban @ 2015-05-07  7:59 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

John Kitchin wrote:
> I have these templates defined in my setup:
>
> ;; * Expansions for blocks [...]
>
> ;; add <sh for shell
> (add-to-list 'org-structure-template-alist
>              '("sh" "#+BEGIN_SRC sh\n?\n#+END_SRC" "<src
> lang=\"shell\">\n?\n</src>"))

Note that the language should be `shell' in Org from Git (not sure about
MELPA, which I don't use). That'll be so in Org 8.3 as well.

Best regards,
  Seb

-- 
Sebastien Vauban

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: paste from clip to code block
  2015-05-07  7:59       ` Sebastien Vauban
@ 2015-09-05 20:15         ` Grant Rettke
  2015-09-07 14:09           ` John Kitchin
  0 siblings, 1 reply; 10+ messages in thread
From: Grant Rettke @ 2015-09-05 20:15 UTC (permalink / raw)
  To: Sebastien Vauban; +Cc: emacs-orgmode@gnu.org

On Thu, May 7, 2015 at 2:59 AM, Sebastien Vauban
<sva-news@mygooglest.com> wrote:
> John Kitchin wrote:
>> I have these templates defined in my setup:

I used my duplicated Org macros as an excuse to learn YASnippet and
came up with this. It is work in progress, but it works. I got tired
of entering a name so many times along with an output file during
exploratory programming in the .emacs.el:
https://github.com/grettke/help/blob/master/yasnippet/org-mode/sc. It
does require learning YAS at some point, and it is worth it.

# -*- mode: snippet -*-
# key: sc
# name: Source Block
# group: HELP
# contributor: gcr@wisdomandwonder.com
# --
#+NAME: ${1:`(org-id-new)`}
#+BEGIN_SRC ${2:$$(yas-choose-value '("emacs-lisp" "org" "sass" "R"
"ditaa" "dot" "plantuml"))}${2:$(when (-contains? '("ditaa" "dot"
"plantuml") yas-text) (concat " :file \\"./image/" (yas-field-value 1)
".png\\""))} $3
$0
#+END_SRC

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: paste from clip to code block
  2015-09-05 20:15         ` Grant Rettke
@ 2015-09-07 14:09           ` John Kitchin
  2015-09-07 16:39             ` Grant Rettke
  0 siblings, 1 reply; 10+ messages in thread
From: John Kitchin @ 2015-09-07 14:09 UTC (permalink / raw)
  To: Grant Rettke; +Cc: Sebastien Vauban, emacs-orgmode@gnu.org

Neat. Do you have some handy way to store a link to the source block, or
jump to them?

Grant Rettke writes:

> On Thu, May 7, 2015 at 2:59 AM, Sebastien Vauban
> <sva-news@mygooglest.com> wrote:
>> John Kitchin wrote:
>>> I have these templates defined in my setup:
>
> I used my duplicated Org macros as an excuse to learn YASnippet and
> came up with this. It is work in progress, but it works. I got tired
> of entering a name so many times along with an output file during
> exploratory programming in the .emacs.el:
> https://github.com/grettke/help/blob/master/yasnippet/org-mode/sc. It
> does require learning YAS at some point, and it is worth it.
>
> # -*- mode: snippet -*-
> # key: sc
> # name: Source Block
> # group: HELP
> # contributor: gcr@wisdomandwonder.com
> # --
> #+NAME: ${1:`(org-id-new)`}
> #+BEGIN_SRC ${2:$$(yas-choose-value '("emacs-lisp" "org" "sass" "R"
> "ditaa" "dot" "plantuml"))}${2:$(when (-contains? '("ditaa" "dot"
> "plantuml") yas-text) (concat " :file \\"./image/" (yas-field-value 1)
> ".png\\""))} $3
> $0
> #+END_SRC

--
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: paste from clip to code block
  2015-09-07 14:09           ` John Kitchin
@ 2015-09-07 16:39             ` Grant Rettke
  2015-09-07 20:18               ` John Kitchin
  0 siblings, 1 reply; 10+ messages in thread
From: Grant Rettke @ 2015-09-07 16:39 UTC (permalink / raw)
  To: John Kitchin; +Cc: Sebastien Vauban, emacs-orgmode@gnu.org

On Mon, Sep 7, 2015 at 9:09 AM, John Kitchin <jkitchin@andrew.cmu.edu> wrote:
> Neat. Do you have some handy way to store a link to the source block, or
> jump to them?

I don't, but please tell us more about what you mean.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: paste from clip to code block
  2015-09-07 16:39             ` Grant Rettke
@ 2015-09-07 20:18               ` John Kitchin
  0 siblings, 0 replies; 10+ messages in thread
From: John Kitchin @ 2015-09-07 20:18 UTC (permalink / raw)
  To: Grant Rettke; +Cc: Sebastien Vauban, emacs-orgmode@gnu.org

For example with the cursor on a src-block press C-c l to store a link
to that name, and later type C-c C-l to insert a link to that
src-block.

It would look a little like this:
#+BEGIN_SRC emacs-lisp
(defun org-src-block-store-link ()
  (let* ((object (org-element-context)))
    (when (equal (org-element-type object) 'src-block)
      (org-store-link-props
       :type "src-block"
       :link (concat "src-block:" (org-element-property :name object))))))

(add-hook 'org-store-link-functions 'org-src-block-store-link)

(org-add-link-type
 "src-block"
 (lambda (label)
   (org-mark-ring-push)
   (widen)
   (goto-char (point-min))
   (re-search-forward (regexp-quote (format "#+NAME: %s" label)))
   (beginning-of-line)))
#+END_SRC

it only works in the current file though.


Grant Rettke writes:

> On Mon, Sep 7, 2015 at 9:09 AM, John Kitchin <jkitchin@andrew.cmu.edu> wrote:
>> Neat. Do you have some handy way to store a link to the source block, or
>> jump to them?
>
> I don't, but please tell us more about what you mean.

--
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2015-09-07 20:19 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-04-17  7:21 paste from clip to code block Xebar Saram
2015-04-17 13:56 ` John Kitchin
2015-04-17 14:36   ` Xebar Saram
2015-04-17 15:08   ` Jorge A. Alfaro-Murillo
2015-04-17 15:17     ` John Kitchin
2015-05-07  7:59       ` Sebastien Vauban
2015-09-05 20:15         ` Grant Rettke
2015-09-07 14:09           ` John Kitchin
2015-09-07 16:39             ` Grant Rettke
2015-09-07 20:18               ` John Kitchin

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.