unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Greg Hill <ghill@synergymicro.com>
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	[thread overview]
Message-ID: <p06002006bd7a1091016b@[10.1.5.75]> (raw)
In-Reply-To: <cf2523f3.0409231402.44ab9a0f@posting.google.com>


[-- Attachment #1.1: Type: text/plain, Size: 3097 bytes --]

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

[-- Attachment #1.2: Type: text/html, Size: 5095 bytes --]

[-- Attachment #2: Type: text/plain, Size: 152 bytes --]

_______________________________________________
Help-gnu-emacs mailing list
Help-gnu-emacs@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gnu-emacs

  parent reply	other threads:[~2004-09-24 18:46 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-09-23  1:05 How to PICK the CTRL-u argument from the file or some other method, with EXAMPLE Jose Cuthberto
2004-09-23 22:02 ` Jose Cuthberto
2004-09-23 22:08   ` Chris F.A. Johnson
2004-09-23 22:50     ` David Golden
2004-09-23 23:42   ` Johan Ur Riise
2004-09-24  7:19   ` Joakim Hove
2004-09-24 18:46   ` Greg Hill [this message]
2004-09-24 19:12     ` Greg Hill
  -- strict thread matches above, loose matches on Subject: below --
2004-09-23 17:01 JayBingham

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='p06002006bd7a1091016b@[10.1.5.75]' \
    --to=ghill@synergymicro.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).