help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Indent first line of each paragraph of file in one hit


From: Rodolfo Medina
Subject: Re: Indent first line of each paragraph of file in one hit
Date: Fri, 25 Nov 2016 11:52:55 +0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)

Rodolfo Medina <address@hidden> writes:

> Konstantin Shakhnov <address@hidden> 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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]