* small function suggestion (org-examplize-region)
@ 2009-03-17 18:02 Eric Schulte
2009-03-17 19:00 ` Manish
2009-03-18 0:50 ` Charles Cave
0 siblings, 2 replies; 8+ messages in thread
From: Eric Schulte @ 2009-03-17 18:02 UTC (permalink / raw)
To: Org Mode List
Hi,
This function could be used to comment out a region of an org-mode file
as an example using the ': ' syntax.
Would this function be a useful addition to org-mode or has this need
already been filled, and I was just unable to find it in the
documentation.
Thanks -- Eric
--8<---------------cut here---------------start------------->8---
(defun org-examplize-region (beg end)
"Comment out region using the ': ' org example quote."
(interactive "*r")
(let ((size (abs (- (line-number-at-pos end)
(line-number-at-pos beg)))))
(if (= size 0)
(let ((result (buffer-substring beg end)))
(delete-region beg end)
(insert (concat ": " result)))
(save-excursion
(goto-char beg)
(dotimes (n size)
(move-beginning-of-line 1) (insert ": ") (forward-line 1))))))
--8<---------------cut here---------------end--------------->8---
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: small function suggestion (org-examplize-region)
2009-03-17 18:02 small function suggestion (org-examplize-region) Eric Schulte
@ 2009-03-17 19:00 ` Manish
2009-03-18 8:38 ` Carsten Dominik
2009-03-18 0:50 ` Charles Cave
1 sibling, 1 reply; 8+ messages in thread
From: Manish @ 2009-03-17 19:00 UTC (permalink / raw)
To: Eric Schulte; +Cc: Org Mode List
On Tue, Mar 17, 2009 at 11:32 PM, Eric Schulte wrote:
> Hi,
>
> This function could be used to comment out a region of an org-mode file
> as an example using the ': ' syntax.
>
> Would this function be a useful addition to org-mode or has this need
> already been filled, and I was just unable to find it in the
> documentation.
>
> Thanks -- Eric
>
> --8<---------------cut here---------------start------------->8---
> (defun org-examplize-region (beg end)
> "Comment out region using the ': ' org example quote."
> (interactive "*r")
> (let ((size (abs (- (line-number-at-pos end)
> (line-number-at-pos beg)))))
> (if (= size 0)
> (let ((result (buffer-substring beg end)))
> (delete-region beg end)
> (insert (concat ": " result)))
> (save-excursion
> (goto-char beg)
> (dotimes (n size)
> (move-beginning-of-line 1) (insert ": ") (forward-line 1))))))
> --8<---------------cut here---------------end--------------->8---
I think org-toggle-fixed-width-section does the same for me.
--
Manish
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: small function suggestion (org-examplize-region)
2009-03-17 18:02 small function suggestion (org-examplize-region) Eric Schulte
2009-03-17 19:00 ` Manish
@ 2009-03-18 0:50 ` Charles Cave
2009-03-18 1:34 ` Nick Dokos
1 sibling, 1 reply; 8+ messages in thread
From: Charles Cave @ 2009-03-18 0:50 UTC (permalink / raw)
To: emacs-orgmode
Eric Schulte <schulte.eric <at> gmail.com> writes:
>
> Hi,
>
> This function could be used to comment out a region of an org-mode file
> as an example using the ': ' syntax.
I just use the prefix-region command of Emacs.
Esc-x prefix-region
then ..
: SPACE RET
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Re: small function suggestion (org-examplize-region)
2009-03-18 0:50 ` Charles Cave
@ 2009-03-18 1:34 ` Nick Dokos
2009-03-18 5:35 ` Charles Cave
0 siblings, 1 reply; 8+ messages in thread
From: Nick Dokos @ 2009-03-18 1:34 UTC (permalink / raw)
To: Charles Cave; +Cc: emacs-orgmode
Charles Cave <charles_cave@optusnet.com.au> wrote:
> Eric Schulte <schulte.eric <at> gmail.com> writes:
>
> >
> > Hi,
> >
> > This function could be used to comment out a region of an org-mode file
> > as an example using the ': ' syntax.
>
> I just use the prefix-region command of Emacs.
>
> Esc-x prefix-region
>
> then ..
>
> : SPACE RET
My emacs (GNU Emacs 23.0.91.1 (i686-pc-linux-gnu, GTK+ Version 2.12.9)
of 2009-03-06 on alphaville.usa.hp.com) doesn't seem to have prefix-region -
where does it come from?
OTOH, it can be simulated with something like this
(let ((fill-prefix ": "))
(indent-region (mark) (point)))
but making it more general (arbitrary prefix) and bullet-proof (not sure
whether (indent-region start end) requires that start be less than end)
would need a bit more code than this.
Thanks,
Nick
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: small function suggestion (org-examplize-region)
2009-03-18 1:34 ` Nick Dokos
@ 2009-03-18 5:35 ` Charles Cave
2009-03-18 8:32 ` Mikael Fornius
2009-03-18 16:07 ` Daniel Clemente
0 siblings, 2 replies; 8+ messages in thread
From: Charles Cave @ 2009-03-18 5:35 UTC (permalink / raw)
To: emacs-orgmode
Nick Dokos <nicholas.dokos <at> hp.com> writes:
> My emacs (GNU Emacs 23.0.91.1 (i686-pc-linux-gnu, GTK+ Version 2.12.9)
> of 2009-03-06 on alphaville.usa.hp.com) doesn't seem to have prefix-region -
> where does it come from?
I forgot that this function is in my .emacs file. I always
thought it was built in to GNU Emacs.
Here it is....
(defun prefix-region (prefix)
"Add a prefix string to each line between mark and point."
(interactive "sPrefix string: ")
(if prefix
(let ((count (count-lines (mark) (point))))
(goto-char (min (mark) (point)))
(while (> count 0)
(setq count (1- count))
(beginning-of-line 1)
(insert prefix)
(end-of-line 1)
(forward-char 1)))))
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: small function suggestion (org-examplize-region)
2009-03-18 5:35 ` Charles Cave
@ 2009-03-18 8:32 ` Mikael Fornius
2009-03-18 16:07 ` Daniel Clemente
1 sibling, 0 replies; 8+ messages in thread
From: Mikael Fornius @ 2009-03-18 8:32 UTC (permalink / raw)
To: Charles Cave; +Cc: emacs-orgmode
I tried the built in emacs function comment-region and it comments out
works with ":" when in org-mode,
GNU Emacs 23.0.91.1 with org 6.24c.
--
Mikael Fornius
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: small function suggestion (org-examplize-region)
2009-03-17 19:00 ` Manish
@ 2009-03-18 8:38 ` Carsten Dominik
0 siblings, 0 replies; 8+ messages in thread
From: Carsten Dominik @ 2009-03-18 8:38 UTC (permalink / raw)
To: Manish; +Cc: Org Mode List
On Mar 17, 2009, at 8:00 PM, Manish wrote:
> On Tue, Mar 17, 2009 at 11:32 PM, Eric Schulte wrote:
>> Hi,
>>
>> This function could be used to comment out a region of an org-mode
>> file
>> as an example using the ': ' syntax.
>>
>> Would this function be a useful addition to org-mode or has this need
>> already been filled, and I was just unable to find it in the
>> documentation.
>>
>> Thanks -- Eric
>>
>> --8<---------------cut here---------------start------------->8---
>> (defun org-examplize-region (beg end)
>> "Comment out region using the ': ' org example quote."
>> (interactive "*r")
>> (let ((size (abs (- (line-number-at-pos end)
>> (line-number-at-pos beg)))))
>> (if (= size 0)
>> (let ((result (buffer-substring beg end)))
>> (delete-region beg end)
>> (insert (concat ": " result)))
>> (save-excursion
>> (goto-char beg)
>> (dotimes (n size)
>> (move-beginning-of-line 1) (insert ": ") (forward-line 1))))))
>> --8<---------------cut here---------------end--------------->8---
>
> I think org-toggle-fixed-width-section does the same for me.
Which is bound to `C-c :'.
- Carsten
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Re: small function suggestion (org-examplize-region)
2009-03-18 5:35 ` Charles Cave
2009-03-18 8:32 ` Mikael Fornius
@ 2009-03-18 16:07 ` Daniel Clemente
1 sibling, 0 replies; 8+ messages in thread
From: Daniel Clemente @ 2009-03-18 16:07 UTC (permalink / raw)
To: Charles Cave; +Cc: emacs-orgmode
El dc, mar 18 2009, Charles Cave va escriure:
>
> (defun prefix-region (prefix)
> "Add a prefix string to each line between mark and point."
> …
To do this I use:
1. Put mark at the first line's beginning and point at the last line's beginning
2. C-x r t
3. Type your prefix, ENTER
,----
| C-x r t runs the command string-rectangle, which is an interactive autoloaded
| Lisp function in `rect.el'.
|
| It is bound to C-x r t.
|
| (string-rectangle START END STRING)
|
| Replace rectangle contents with STRING on each line.
| The length of STRING need not be the same as the rectangle width.
`----
It allows not only to prefix but also to „infix“ and „suffix“, and to replace rectangles of text.
Also nice is C-x r k, to delete a rectangular region.
And C-x r y, etc.
-- Daniel
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2009-03-18 16:07 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-03-17 18:02 small function suggestion (org-examplize-region) Eric Schulte
2009-03-17 19:00 ` Manish
2009-03-18 8:38 ` Carsten Dominik
2009-03-18 0:50 ` Charles Cave
2009-03-18 1:34 ` Nick Dokos
2009-03-18 5:35 ` Charles Cave
2009-03-18 8:32 ` Mikael Fornius
2009-03-18 16:07 ` Daniel Clemente
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).