* Indent first line of each paragraph of file in one hit
@ 2016-11-24 15:35 Rodolfo Medina
2016-11-24 22:44 ` Rodolfo Medina
2016-11-25 10:48 ` Konstantin Shakhnov
0 siblings, 2 replies; 11+ messages in thread
From: Rodolfo Medina @ 2016-11-24 15:35 UTC (permalink / raw)
To: help-gnu-emacs
Hi to all Emacs users.
Suppose you have a large file, in which the first line of each paragraph is not
indented; and want it to be with one single command for the whole file. Is
that possible, and how?
Thanks for any help,
Rodolfo
^ permalink raw reply [flat|nested] 11+ messages in thread
* Indent first line of each paragraph of file in one hit
@ 2016-11-24 20:18 Rodolfo Medina
2016-11-25 11:34 ` Andreas Röhler
0 siblings, 1 reply; 11+ messages in thread
From: Rodolfo Medina @ 2016-11-24 20:18 UTC (permalink / raw)
To: help-gnu-emacs
Hi to all Emacs users.
Suppose you have a large file, in which the first line of each paragraph is not
indented; and want it to be with one single command for the whole file. Is
that possible, and how?
Thanks for any help,
Rodolfo
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Indent first line of each paragraph of file in one hit
2016-11-24 15:35 Indent first line of each paragraph of file in one hit Rodolfo Medina
@ 2016-11-24 22:44 ` Rodolfo Medina
2016-11-25 10:48 ` Konstantin Shakhnov
1 sibling, 0 replies; 11+ messages in thread
From: Rodolfo Medina @ 2016-11-24 22:44 UTC (permalink / raw)
To: help-gnu-emacs
Rodolfo Medina <rodolfo.medina@gmail.com> writes:
> Suppose you have a large file, in which the first line of each paragraph is
> not indented; and want it to be with one single command for the whole file.
> Is that possible, and how?
Sorry for multiple posting, I thought my message had not been delivered to the
list because of technical problems.
Rodolfo
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Indent first line of each paragraph of file in one hit
2016-11-24 15:35 Indent first line of each paragraph of file in one hit Rodolfo Medina
2016-11-24 22:44 ` Rodolfo Medina
@ 2016-11-25 10:48 ` Konstantin Shakhnov
2016-11-25 11:28 ` Rodolfo Medina
1 sibling, 1 reply; 11+ messages in thread
From: Konstantin Shakhnov @ 2016-11-25 10:48 UTC (permalink / raw)
To: Rodolfo Medina; +Cc: help-gnu-emacs
On Thu, Nov 24, 2016 at 03:35:12PM +0000, Rodolfo Medina wrote:
> Suppose you have a large file, in which the first line of each paragraph is not
> indented; and want it to be with one single command for the whole file. Is
> that possible, and how?
I'm not great lisp master, but this dirty sketches works (just replace
">>>>" to what you need at the beginning of line):
;; Variant 1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun my-indent-first-line1 ()
"Indent the first line of each paragraph"
(interactive)
(goto-char (point-min))
(while (not (= (point) (point-max)))
(forward-paragraph)
(next-line)
(insert ">>>>")
(fill-paragraph)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(fill-paragraph) - is optional, delete it if you don't want refill
paragraph after inserting
;; Variant 2 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun my-indent-first-line2 ()
"Indent the first line of each paragraph"
(interactive)
(replace-regexp "\n\n" "\n\n>>>>" nil (point-min) (point-max)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Indent first line of each paragraph of file in one hit
2016-11-25 10:48 ` Konstantin Shakhnov
@ 2016-11-25 11:28 ` Rodolfo Medina
2016-11-25 11:52 ` Rodolfo Medina
0 siblings, 1 reply; 11+ messages in thread
From: Rodolfo Medina @ 2016-11-25 11:28 UTC (permalink / raw)
To: Konstantin Shakhnov; +Cc: help-gnu-emacs
Konstantin Shakhnov <kastian@mail.ru> writes:
> On Thu, Nov 24, 2016 at 03:35:12PM +0000, Rodolfo Medina wrote:
>> Suppose you have a large file, in which the first line of each paragraph is
>> not indented; and want it to be with one single command for the whole file.
>> Is that possible, and how?
>
> I'm not great lisp master, but this dirty sketches works (just replace
> ">>>>" to what you need at the beginning of line):
>
> ;; Variant 1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> (defun my-indent-first-line1 ()
> "Indent the first line of each paragraph"
> (interactive)
> (goto-char (point-min))
> (while (not (= (point) (point-max)))
> (forward-paragraph)
> (next-line)
> (insert ">>>>")
> (fill-paragraph)))
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>
> (fill-paragraph) - is optional, delete it if you don't want refill
> paragraph after inserting
>
> ;; Variant 2 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> (defun my-indent-first-line2 ()
> "Indent the first line of each paragraph"
> (interactive)
> (replace-regexp "\n\n" "\n\n>>>>" nil (point-min) (point-max)))
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Thanks, it seems to work fine. But please now suppose that I want that command
to act only upon the paragraph where the cursor is now and not on the rest of
the document.
Thanks,
Rodolfo
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Indent first line of each paragraph of file in one hit
2016-11-24 20:18 Rodolfo Medina
@ 2016-11-25 11:34 ` Andreas Röhler
0 siblings, 0 replies; 11+ messages in thread
From: Andreas Röhler @ 2016-11-25 11:34 UTC (permalink / raw)
To: help-gnu-emacs
On 24.11.2016 21:18, Rodolfo Medina wrote:
> Hi to all Emacs users.
>
> Suppose you have a large file, in which the first line of each paragraph is not
> indented; and want it to be with one single command for the whole file. Is
> that possible, and how?
>
> Thanks for any help,
>
> Rodolfo
>
Don't see a library ready to it. But yes, it would be possible to fill
the first line, then proceed with the remaining paragraph, jump to the
next. A keybord-macro might do it already.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Indent first line of each paragraph of file in one hit
2016-11-25 11:28 ` Rodolfo Medina
@ 2016-11-25 11:52 ` Rodolfo Medina
2016-11-25 12:15 ` Konstantin Shakhnov
0 siblings, 1 reply; 11+ messages in thread
From: Rodolfo Medina @ 2016-11-25 11:52 UTC (permalink / raw)
To: Konstantin Shakhnov; +Cc: help-gnu-emacs
Rodolfo Medina <rodolfo.medina@gmail.com> writes:
> Konstantin Shakhnov <kastian@mail.ru> writes:
>
>> On Thu, Nov 24, 2016 at 03:35:12PM +0000, Rodolfo Medina wrote:
>>> Suppose you have a large file, in which the first line of each paragraph is
>>> not indented; and want it to be with one single command for the whole file.
>>> Is that possible, and how?
>>
>> I'm not great lisp master, but this dirty sketches works (just replace
>> ">>>>" to what you need at the beginning of line):
>>
>> ;; Variant 1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>> (defun my-indent-first-line1 ()
>> "Indent the first line of each paragraph"
>> (interactive)
>> (goto-char (point-min))
>> (while (not (= (point) (point-max)))
>> (forward-paragraph)
>> (next-line)
>> (insert ">>>>")
>> (fill-paragraph)))
>> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>>
>> (fill-paragraph) - is optional, delete it if you don't want refill
>> paragraph after inserting
>>
>> ;; Variant 2 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>> (defun my-indent-first-line2 ()
>> "Indent the first line of each paragraph"
>> (interactive)
>> (replace-regexp "\n\n" "\n\n>>>>" nil (point-min) (point-max)))
>> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>
>
> Thanks, it seems to work fine. But please now suppose that I want that
> command to act only upon the paragraph where the cursor is now and not on the
> rest of the document.
This seems to work:
(defun my-indent-first-line1 ()
"Indent the first line of each paragraph"
(interactive)
(backward-paragraph)
(next-line)
(insert " ")
(fill-paragraph)
)
Rodolfo
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Indent first line of each paragraph of file in one hit
2016-11-25 11:52 ` Rodolfo Medina
@ 2016-11-25 12:15 ` Konstantin Shakhnov
2016-11-25 12:20 ` Rodolfo Medina
0 siblings, 1 reply; 11+ messages in thread
From: Konstantin Shakhnov @ 2016-11-25 12:15 UTC (permalink / raw)
To: Rodolfo Medina; +Cc: help-gnu-emacs
On Fri, Nov 25, 2016 at 11:52:55AM +0000, Rodolfo Medina wrote:
> This seems to work:
>
> (defun my-indent-first-line1 ()
> "Indent the first line of each paragraph"
> (interactive)
> (backward-paragraph)
> (next-line)
> (insert " ")
> (fill-paragraph)
> )
Yes, I've just made something similar. But there is a trap - if your
file doesn't starts with '\n' you'll get wrong indentation of the
first paraghaph
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
The Shire at this time had hardly any 'government'. Families for the
>>>>>most part managed their own affairs. Growing food and eating it
occupied most of their time. In other matters they were, as a rule,
....
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Indent first line of each paragraph of file in one hit
2016-11-25 12:15 ` Konstantin Shakhnov
@ 2016-11-25 12:20 ` Rodolfo Medina
2016-11-25 12:45 ` Konstantin Shakhnov
0 siblings, 1 reply; 11+ messages in thread
From: Rodolfo Medina @ 2016-11-25 12:20 UTC (permalink / raw)
To: Konstantin Shakhnov; +Cc: help-gnu-emacs
Konstantin Shakhnov <kastian@mail.ru> writes:
> On Fri, Nov 25, 2016 at 11:52:55AM +0000, Rodolfo Medina wrote:
>> This seems to work:
>>
>> (defun my-indent-first-line1 ()
>> "Indent the first line of each paragraph"
>> (interactive)
>> (backward-paragraph)
>> (next-line)
>> (insert " ")
>> (fill-paragraph)
>> )
>
>
> Yes, I've just made something similar. But there is a trap - if your
> file doesn't starts with '\n' you'll get wrong indentation of the
> first paraghaph
Yes, I see. No way to avoid that?
Rodolfo
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Indent first line of each paragraph of file in one hit
2016-11-25 12:20 ` Rodolfo Medina
@ 2016-11-25 12:45 ` Konstantin Shakhnov
2016-11-25 15:39 ` [solved] " Rodolfo Medina
0 siblings, 1 reply; 11+ messages in thread
From: Konstantin Shakhnov @ 2016-11-25 12:45 UTC (permalink / raw)
To: help-gnu-emacs
On Fri, Nov 25, 2016 at 12:20:45PM +0000, Rodolfo Medina wrote:
> Konstantin Shakhnov <kastian@mail.ru> writes:
> > Yes, I've just made something similar. But there is a trap - if your
> > file doesn't starts with '\n' you'll get wrong indentation of the
> > first paraghaph
> Yes, I see. No way to avoid that?
(defun my-indent-first-line ()
"Indent the first line of current paragraph"
(interactive)
(backward-paragraph)
(if (= (line-beginning-position) (line-end-position)) ; if line not empty
(next-line))
(insert ">>>>")
(fill-paragraph))
Not very nice, but seems working.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [solved] Re: Indent first line of each paragraph of file in one hit
2016-11-25 12:45 ` Konstantin Shakhnov
@ 2016-11-25 15:39 ` Rodolfo Medina
0 siblings, 0 replies; 11+ messages in thread
From: Rodolfo Medina @ 2016-11-25 15:39 UTC (permalink / raw)
To: Konstantin Shakhnov; +Cc: help-gnu-emacs
Konstantin Shakhnov <kastian@mail.ru> writes:
> On Fri, Nov 25, 2016 at 12:20:45PM +0000, Rodolfo Medina wrote:
>> Konstantin Shakhnov <kastian@mail.ru> writes:
>> > Yes, I've just made something similar. But there is a trap - if your
>> > file doesn't starts with '\n' you'll get wrong indentation of the
>> > first paraghaph
>> Yes, I see. No way to avoid that?
>
> (defun my-indent-first-line ()
> "Indent the first line of current paragraph"
> (interactive)
> (backward-paragraph)
> (if (= (line-beginning-position) (line-end-position)) ; if line not empty
> (next-line))
> (insert ">>>>")
> (fill-paragraph))
>
> Not very nice, but seems working.
Thanks! Константин also provided this:
(defun my-indent-first-line-of-all-paragraphs ()
"Indent the first line of each paragraph"
(interactive)
(save-excursion
(goto-char (point-min))
(while (not (= (point) (point-max)))
(if (= (line-beginning-position) (line-end-position)) ; if empty line
(next-line))
(insert ">>>>")
(fill-paragraph)
(forward-paragraph))))
(global-set-key (kbd "C-c i") 'my-indent-all-paragraphs)
(defun my-indent-first-line-of-current-paragraph ()
"Indent the first line of current paragraph"
(interactive)
(backward-paragraph)
(if (= (line-beginning-position) (line-end-position))
(next-line))
(insert ">>>>")
(fill-paragraph))
(global-set-key (kbd "M-p") 'my-indent-first-line)
Thanks to all for these splendid solutions.
Cheers,
Rodolfo
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2016-11-25 15:39 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-24 15:35 Indent first line of each paragraph of file in one hit Rodolfo Medina
2016-11-24 22:44 ` Rodolfo Medina
2016-11-25 10:48 ` Konstantin Shakhnov
2016-11-25 11:28 ` Rodolfo Medina
2016-11-25 11:52 ` Rodolfo Medina
2016-11-25 12:15 ` Konstantin Shakhnov
2016-11-25 12:20 ` Rodolfo Medina
2016-11-25 12:45 ` Konstantin Shakhnov
2016-11-25 15:39 ` [solved] " Rodolfo Medina
-- strict thread matches above, loose matches on Subject: below --
2016-11-24 20:18 Rodolfo Medina
2016-11-25 11:34 ` Andreas Röhler
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.