emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Xebar Saram <zeltakc@gmail.com>
To: Thorsten Jolitz <tjolitz@gmail.com>
Cc: org mode <emacs-orgmode@gnu.org>
Subject: Re: [RFC] Add commmand for wrapping sexp/region in src-blocks to Org?
Date: Sat, 2 Aug 2014 11:44:28 +0300	[thread overview]
Message-ID: <CAOQHXPoMhLSgaxZ5tfT2AK7xwxf7yNAT4XWF2qhRYQ0VJdKEtQ@mail.gmail.com> (raw)
In-Reply-To: <87k36wqirh.fsf@gmail.com>

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

Hi Thorsten and list

How are you?

small question. ive been using your amazing function daily last few days
and been lovin' it :)

i wonder if i could request a tiny related feature (this may be very easy
to do already).
i would like to assign hotkeys for 2 scenarios:

1) pre selected language for 1 line
2) pre selected language prompting for number of lines to wrap

so IE id assign F9-b to auto wrap current line with bash syntax while F9-l
would wrap in lisp
also F10-b would prompt me how man lines to wrap in bash etc

is that possible? thanks you again for all your wonderful work

kind regards

z



On Tue, Jul 29, 2014 at 6:36 PM, Thorsten Jolitz <tjolitz@gmail.com> wrote:

>
> Hi List,
>
> I often missed the following command for wrapping existing content into
> src-blocks in the past, besides knowing about
> `org-babel-demarcate-block' and easy template insertion. Would it make
> sense to add it to Org-mode?
>
> I made it cover several use cases:
>
>   - Wrap sexp at point - perfect when on first paren of a nested list,
>     or when a string should be wrapped in a programming-mode, or a
>     word in a text-mode.
>
>   - Wrap region between point and +/- N lines forward/backward (very
>     fast because no point movement is involved).
>
>   - Wrap active region.
>
> Usage:
>
> 1. wrap active region or (if none) sexp-at-point in emacs-lisp src-block
>
> ,----
> | M-x org-wrap-in-src-block
> `----
>
> 2. wrap active region or (if none) sexp-at-point in src-block, prompt
>    user for Org-Babel language
>
> ,----
> | C-u M-x org-wrap-in-src-block
> `----
>
> 3. prompt user for Org-Babel language and number of lines to wrap
> (forward or backward)
>
> ,----
> | C-u C-u M-x org-wrap-in-src-block
> `----
>
>
> #+begin_src emacs-lisp
> (defun org-wrap-in-src-block (&optional lang lines)
>   "Wrap sexp-at-point or region in src-block.
>
> Use Org-Babel LANGuage for the src-block if given, Emacs-Lisp
> otherwise. A region instead of the sexp-at-point is wrapped if
> either
>
>    - optional argument LINES is an (positive or negative) integer
>    - or the region is active
>
> In the first case the region is determined by moving +/- LINES
> forward/backward from point using `forward-line', in the second
> case the active region is used.
>
> When called with prefix argument 'C-u', prompt the user for the
> Org-Babel language to use. When called with two prefix arguments
> 'C-u C-u', prompt the user for both the Org-Babel language to use
> and the number of lines to be wrapped."
>   (interactive
>    (cond
>     ((equal current-prefix-arg nil) nil)
>     ((equal current-prefix-arg '(4))
>      (list
>       (ido-completing-read "Org-Babel language: "
>                            (mapcar
>                             (lambda (--lang)
>                               (symbol-name (car --lang)))
>                             org-babel-load-languages)
>                            nil nil nil nil "emacs-lisp")))
>     ((equal current-prefix-arg '(16))
>      (list
>       (ido-completing-read "Org-Babel language: "
>                            (mapcar
>                             (lambda (--lang)
>                               (symbol-name (car --lang)))
>                             org-babel-load-languages)
>                            nil nil nil nil "emacs-lisp")
>       (read-number "Number of lines to wrap: " 1)))))
>   (let* ((language (or lang "emacs-lisp"))
>          (beg (or (and (not lines)
>                        (region-active-p)
>                        (region-beginning))
>                   (point)))
>          (marker (save-excursion (goto-char beg) (point-marker)))
>          (bol (save-excursion (goto-char beg) (bolp)))
>          (end (cond
>                (lines (save-excursion
>                         (forward-line lines) (point)))
>                ((region-active-p)(region-end))
>                (t (save-excursion
>                     (forward-sexp) (point)))))
>          (cut-strg (buffer-substring beg end)))
>     (delete-region beg end)
>     (goto-char (marker-position marker))
>     (insert
>      (format
>       "%s#+begin_src %s\n%s%s#+end_src\n"
>       (if (or (and lines (< lines 0)) bol) "" "\n")
>       language
>       cut-strg
>       (if lines "" "\n")))
>     (set-marker marker nil)))
> #+end_src
>
> --
> cheers,
> Thorsten
>
>
>

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

  parent reply	other threads:[~2014-08-02  8:44 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-29 15:36 [RFC] Add commmand for wrapping sexp/region in src-blocks to Org? Thorsten Jolitz
2014-07-30  9:23 ` Alan Schmitt
2014-08-02  8:44 ` Xebar Saram [this message]
2014-08-05 13:15   ` Thorsten Jolitz
2014-08-06 11:43     ` Xebar Saram
2014-08-06 12:14       ` Thorsten Jolitz
2014-08-06 12:25         ` Xebar Saram
2014-08-02  9:25 ` Nicolas Goaziou
2014-08-05 13:19   ` Thorsten Jolitz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAOQHXPoMhLSgaxZ5tfT2AK7xwxf7yNAT4XWF2qhRYQ0VJdKEtQ@mail.gmail.com \
    --to=zeltakc@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=tjolitz@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).