Article View: gnu.emacs.help
Article #189263Re: Line oriented commands?
From: Joe Wells
Date: Fri, 22 Mar 1991 17:39
Date: Fri, 22 Mar 1991 17:39
61 lines
2529 bytes
2529 bytes
In article <FWP1.91Mar22004323@Jester.CC.MsState.Edu> fwp1@CC.MsState.Edu (Frank Peters) writes:
Note, I am assuming you always want to operate on whole lines in the stuff
below:
Frank> run this command on lines 5 through 37
M-x goto-line RET 5 RET C-SPC M-x goto-line RET 37 RET C-e C-x n C-x C-x
C-x ( C-a [... operate on line ...] C-e C-f C-x ) M-0 C-x e C-x w
Frank> run this command on lines from the beginning of the file to here
C-e M-< C-x n C-x ( C-a [... operate on line ...] C-e C-f C-x ) M-0 C-x e
C-x w
Frank> run this command on lines from here to 47
Assuming 47 is after this line:
C-a C-SPC M-x goto-line RET 47 RET C-x n C-x C-x C-x ( C-a
[... operate on line ...] C-e C-f C-x ) M-0 C-x e C-x w
Frank> run this command from mark a to mark b
I assume you mean register a and b?
Assuming a before b:
C-x j a C-a C-SPC C-x j b C-e C-x n C-x C-x C-x ( C-a
[... operate on line ...] C-e C-f C-x ) M-0 C-x e C-x w
Frank> What I'm hoping to find is a function that automates the process
Frank> somewhat.
If you want to do it in Lisp, the key function is narrow-to-region:
(defun operate-on-lines-in-region (beg end func)
(save-excursion
(save-restriction
(narrow-to-region (progn (goto-char beg)
(beginning-of-line)
(point))
(progn (goto-char end)
(end-of-line)
(point)))
(goto-char beg)
(while (not (eobp))
(funcall func)
(forward-line 1)))))
This probably isn't a capability in much demand by emacs users but 6
years of editing with line editors and vi have gotten me extremely
used to having this.
On the contrary, Emacs users use this feature all the time, both
interactively and in Lisp.
--
Enjoy,
Joe Wells <jbw@bu.edu>
Technical Details
Message-ID:
<JBW.91Mar22123956@bigbird.bu.edu>Path:
arc1-ca.pugleaf.net!gmdzi!unido!fauern!ira.uka.de!sol.ctr.columbia.edu!zaphod.mps.ohio-state.edu!think.com!snorkelwacker.mit.edu!bu.edu!nntp-read!jbwReferences:
<FWP1.91Mar22004323@Jester.CC.MsState.Edu>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103b8b,6e991245ce22b1bb X-Google-Attributes: gid103b8b,public X-Google-ArrivalTime: 1991-03-22 21:06:43 PST Path: arc1-ca.pugleaf.net!gmdzi!unido!fauern!ira.uka.de!sol.ctr.columbia.edu!zaphod.mps.ohio-state.edu!think.com!snorkelwacker.mit.edu!bu.edu!nntp-read!jbw From: jbw@bigbird.bu.edu (Joe Wells) Newsgroups: gnu.emacs.help Subject: Re: Line oriented commands? Message-ID: <JBW.91Mar22123956@bigbird.bu.edu> Date: 22 Mar 91 17:39:56 GMT References: <FWP1.91Mar22004323@Jester.CC.MsState.Edu> Sender: news@bu.edu.bu.edu Distribution: gnu Organization: Boston University Computer Science Department Lines: 61 In-reply-to: fwp1@CC.MsState.Edu's message of 22 Mar 91 06:43:23 GMT