Re: [O] paste from clip to code block

2015-09-07 Thread John Kitchin
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
>  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: g...@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



Re: [O] paste from clip to code block

2015-09-07 Thread Grant Rettke
On Mon, Sep 7, 2015 at 9:09 AM, John Kitchin  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.



Re: [O] paste from clip to code block

2015-09-07 Thread John Kitchin
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  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



Re: [O] paste from clip to code block

2015-09-05 Thread Grant Rettke
On Thu, May 7, 2015 at 2:59 AM, Sebastien Vauban
 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: g...@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



Re: [O] paste from clip to code block

2015-05-07 Thread Sebastien Vauban
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




[O] paste from clip to code block

2015-04-17 Thread Xebar Saram
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


Re: [O] paste from clip to code block

2015-04-17 Thread Xebar Saram
thx john

that are very helpful tips!

Z

On Fri, Apr 17, 2015 at 4:56 PM, John Kitchin jkitc...@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



Re: [O] paste from clip to code block

2015-04-17 Thread John Kitchin
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



Re: [O] paste from clip to code block

2015-04-17 Thread Jorge A. Alfaro-Murillo

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.




Re: [O] paste from clip to code block

2015-04-17 Thread John Kitchin
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-muri...@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.