From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Greg Hill Newsgroups: gmane.emacs.help Subject: Re: How to PICK the CTRL-u argument from the file or some other method, with EXAMPLE Date: Fri, 24 Sep 2004 11:46:49 -0700 Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: References: NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1384239665==" X-Trace: sea.gmane.org 1096051648 26697 80.91.229.6 (24 Sep 2004 18:47:28 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 24 Sep 2004 18:47:28 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Sep 24 20:47:14 2004 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1CAv69-0006qn-00 for ; Fri, 24 Sep 2004 20:47:14 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1CAvCF-0002Zv-Cj for geh-help-gnu-emacs@m.gmane.org; Fri, 24 Sep 2004 14:53:31 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1CAvC3-0002Ze-BY for help-gnu-emacs@gnu.org; Fri, 24 Sep 2004 14:53:19 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1CAvC1-0002YF-DB for help-gnu-emacs@gnu.org; Fri, 24 Sep 2004 14:53:19 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1CAvC0-0002Xr-MH for help-gnu-emacs@gnu.org; Fri, 24 Sep 2004 14:53:16 -0400 Original-Received: from [207.158.54.5] (helo=renfield.synergymicro.com) by monty-python.gnu.org with esmtp (TLSv1:DES-CBC3-SHA:168) (Exim 4.34) id 1CAv5t-0001yY-Gu for help-gnu-emacs@gnu.org; Fri, 24 Sep 2004 14:46:57 -0400 Original-Received: from synergy.san.synergymicro.com (synergy.san.synergymicro.com [10.1.2.12]) by renfield.synergymicro.com (8.12.10/8.12.10) with ESMTP id i8OInt9f026110 for ; Fri, 24 Sep 2004 11:49:55 -0700 Original-Received: from [10.1.5.75] ([10.1.5.75]) by synergy.san.synergymicro.com (8.12.10/8.12.10) with ESMTP id i8OIlxkK024516 for ; Fri, 24 Sep 2004 11:47:59 -0700 In-Reply-To: Original-To: help-gnu-emacs@gnu.org X-Virus-Scanned: clamd / ClamAV version 0.70, clamav-milter version 0.70j X-CanItPRO-Stream: default X-Canit-Stats-ID: 272880 - 0f488681c453 X-Scanned-By: CanIt (www . canit . ca) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.help:20869 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:20869 --===============1384239665== Content-Type: multipart/alternative; boundary="============_-1116070886==_ma============" --============_-1116070886==_ma============ Content-Type: text/plain; charset="us-ascii" ; format="flowed" At 3:02 PM -0700 9/23/04, Jose Cuthberto wrote: >jose@Aumara.zzn.com (Jose Cuthberto) wrote in message >news:... >> An example would clarify the problem: >> >> Suppose you want to paste a single killed line (in kill buffer >>using two C-k's) >> you can trivially do it like this: >> >> C-u 2 C-y >> This does not do the same thing as typing "C-y" twice, which is what you imply it does. > > In this case you had to enter the numbers. >> >> I have a file like this: >> >> 5 >> line1 >> 6 >> line2 >> >> Now I must convert it to a file with 5 line1's and 6 line2's and so on. >> It is a long file. >> >> How do I pick 5 and put it into C-u so that it is done 5 times. >> You can't. > > I can write macros. and I can also write single line lisp functions. >> Unfortunately there is no yank cammand that can take the argument 5. >> nor do i know the lisp function that can take the count and pass it to >> lisp function yank. I would want to avoid writing a loops, and vars etc. >> Too bad. > > Thanks to the star who can help!!! >> >> jose > >still waiting for a solution You should seriously consider learning how to do a bit more than just write macros and "single line lisp functions." You would get a lot more help if you at least made a good-faith effort to write your own function, presented the best you could come up with to the forum, and asked for tips on making it better. Here's a fish. Study it and try to learn something. Execute it using M-x or bind it to a keystroke. (defun expand-file (from-file to-file &optional replace) "Expand alternating count and text lines from FROM-FILE to TO-FILE. Interactively prompts for file names. If REPLACE (command prefix), replaces previous contents of TO-FILE, otherwise appends to its end. If FROM-FILE is already in a buffer when command is invoked, expansion starts from the current position of point. Otherwise it starts from the top of the file. When done, selects TO-FILE for the current window but does not automatically save it." (interactive "fExpand from file: \nFto file: \nP") (let (from-buf to_buf count line) (setq from-buf (find-file-noselect from-file) to-buf (find-file-noselect to-file) ) (set-buffer to-buf) (if replace (erase-buffer) (end-of-buffer) ) (set-buffer from-buf) (while (looking-at "[0-9]+$") (setq count (read (current-buffer))) (forward-line 1) (setq line (buffer-substring-no-properties (point) (1+ (line-end-position)))) (forward-line 1) (set-buffer to-buf) (while (> count 0) (insert line) (setq count (1- count)) ) (set-buffer from-buf) ) (find-file to-file) (set-buffer from-buf) (save-excursion (skip-chars-forward " \t\n") (if (not (eobp)) (progn (message "Warning: non-integer line count in %s. Expansion stops." from-file) (switch-to-buffer-other-window from-buf) ) ) ) )) --Greg --============_-1116070886==_ma============ Content-Type: text/html; charset="us-ascii" Re: How to PICK the CTRL-u argument from the file or some
At 3:02 PM -0700 9/23/04, Jose Cuthberto wrote:
jose@Aumara.zzn.com (Jose Cuthberto) wrote in message news:<cf2523f3.0409221705.73716a7d@posting.google.com>...
> An example would clarify the problem:
>
> Suppose you want to paste a single killed line (in kill buffer using two C-k's)
> you can trivially do it like this:
>
> C-u 2 C-y
>

This does not do the same thing as typing "C-y" twice, which is what you imply it does.

> In this case you had to enter the numbers.
>
> I have a file like this:
>
> 5
> line1
> 6
> line2
>
> Now I must convert it to a file with 5 line1's and 6 line2's and so on.
> It is a long file.
>
> How do I pick 5 and put it into C-u so that it is done 5 times.
>

You can't.

> I can write macros. and I can also write single line lisp functions.
> Unfortunately there is no yank cammand that can take the argument 5.
> nor do i know the lisp function that can take the count and pass it to
> lisp function yank. I would want to avoid writing a loops, and vars etc.
>

Too bad.

> Thanks to the star who can help!!!
>
> jose
still waiting for a solution

You should seriously consider learning how to do a bit more than just write macros and "single line lisp functions."  You would get a lot more help if you at least made a good-faith effort to write your own function, presented the best you could come up with to the forum, and asked for tips on making it better.

Here's a fish.  Study it and try to learn something.  Execute it using M-x or bind it to a keystroke.

(defun expand-file (from-file to-file &optional replace)
  "Expand alternating count and text lines from FROM-FILE to TO-FILE.
Interactively prompts for file names.
If REPLACE (command prefix), replaces previous contents of TO-FILE,
otherwise appends to its end.
If FROM-FILE is already in a buffer when command is invoked, expansion
starts from the current position of point.  Otherwise it starts from
the top of the file.
When done, selects TO-FILE for the current window but does not
automatically save it."
  (interactive "fExpand from file: \nFto file: \nP")
  (let (from-buf to_buf count line)
    (setq from-buf (find-file-noselect from-file)
          to-buf (find-file-noselect to-file) )
    (set-buffer to-buf)
    (if replace
        (erase-buffer)
      (end-of-buffer) )
    (set-buffer from-buf)
    (while (looking-at "[0-9]+$")
      (setq count (read (current-buffer)))
      (forward-line 1)
      (setq line (buffer-substring-no-properties
                  (point) (1+ (line-end-position))))
      (forward-line 1)
      (set-buffer to-buf)
      (while (> count 0)
        (insert line)
        (setq count (1- count)) )
      (set-buffer from-buf) )
    (find-file to-file)
    (set-buffer from-buf)
    (save-excursion
      (skip-chars-forward " \t\n")
      (if (not (eobp))
          (progn
            (message "Warning: non-integer line count in %s. Expansion stops."
                     from-file)
            (switch-to-buffer-other-window from-buf) ) ) ) ))
 
--Greg
--============_-1116070886==_ma============-- --===============1384239665== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Help-gnu-emacs mailing list Help-gnu-emacs@gnu.org http://lists.gnu.org/mailman/listinfo/help-gnu-emacs --===============1384239665==--