unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* How to PICK the CTRL-u argument from the file or some other method, with EXAMPLE
@ 2004-09-23  1:05 Jose Cuthberto
  2004-09-23 22:02 ` Jose Cuthberto
  0 siblings, 1 reply; 9+ messages in thread
From: Jose Cuthberto @ 2004-09-23  1:05 UTC (permalink / raw)


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

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.

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.

Thanks to the star who can help!!!

jose

^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: How to PICK the CTRL-u argument from the file or some other method, with EXAMPLE
@ 2004-09-23 17:01 JayBingham
  0 siblings, 0 replies; 9+ messages in thread
From: JayBingham @ 2004-09-23 17:01 UTC (permalink / raw)


On Wednesday, September 22, 2004 8:06 PM Jose Cuthberto wrote:

> 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
> 
> 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.
> 
> 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.

I don't know which version of emacs you are using or if you are even
using emacs, but in emacs 21.2 what it appears that you describe as
occurring when you type C-u 2 C-y is not what happens when I type the
same.  What does happen is that the second most recent item in the
kill ring is inserted into the buffer, not two copies of the most
recent item in the kill ring.

So assuming that you are using emacs, I don't think that you can do
what you think you want to do in the way you think you want to do it.
 IMHO it looks to me like you just need overcome your fear of loops
and to learn how to write elisp functions.  It is all that painful.
;)

If you need help learning how to program emacs lisp there are
tutorials on the web.  I did a quick search for "emacs lisp"+tutorial
and found at least 33 sites that matched, including the one on the
GNU site at:
http://www.gnu.org/software/emacs/emacs-lisp-intro/html_mono/emacs-lisp-intro.html.

You should have access to the Emacs Lisp Reference Manual.  Some sites
put it in the info directory so it is available when you type C-h i,
if yours does not it is available on the web at:
http://www.gnu.org/software/emacs/elisp-manual/

<Send replies only to the list not to this address>

-_
J_)
C_)ingham
.    Hewlett-Packard
.    Austin, TX
. “Language is the apparel in which your thoughts parade in public.
.  Never clothe them in vulgar and shoddy attire.”     -Dr. George W.
Crane-

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: How to PICK the CTRL-u argument from the file or some other method, with EXAMPLE
  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
                     ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Jose Cuthberto @ 2004-09-23 22:02 UTC (permalink / raw)


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
> 
> 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.
> 
> 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.
> 
> Thanks to the star who can help!!!
> 
> jose


still waiting for a solution

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: How to PICK the CTRL-u argument from the file or some other method, with EXAMPLE
  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
                     ` (2 subsequent siblings)
  3 siblings, 1 reply; 9+ messages in thread
From: Chris F.A. Johnson @ 2004-09-23 22:08 UTC (permalink / raw)


On 2004-09-23, 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
>> 
>> 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.
>> 
>> 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.
>> 
>> Thanks to the star who can help!!!
>
> still waiting for a solution

    Still wondering why it was posted to comp.unix.shell.

-- 
    Chris F.A. Johnson                  http://cfaj.freeshell.org/shell
    ===================================================================
    My code (if any) in this post is copyright 2004, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: How to PICK the CTRL-u argument from the file or some other method, with EXAMPLE
  2004-09-23 22:08   ` Chris F.A. Johnson
@ 2004-09-23 22:50     ` David Golden
  0 siblings, 0 replies; 9+ messages in thread
From: David Golden @ 2004-09-23 22:50 UTC (permalink / raw)


Chris F.A. Johnson wrote:

>> still waiting for a solution
> 
>     Still wondering why it was posted to comp.unix.shell.
> 

Heh. Remember it IS emacs, after all. It IS (or typically includes "out-of-box"
an implementation of) an sh-family shell called eshell. 

http://www.newartisans.com/johnw/eshell.html
"""
Eshell is a command shell implemented entirely in Emacs Lisp. It invokes no external 
processes beyond those requested by the user. It is intended to be a functional 
replacement for command shells such as bash, zsh, rc, 4dos; since Emacs itself is
capable of handling most of the tasks accomplished by such tools. 
"""


So, on your average linux install (okay for the pedants, linux is not unix exactly,
but emacs works on real unix too) one can do the following (tested, actual
copy+pastes from my system):

# adduser tryme
# chsh -s /usr/bin/emacs tryme
# su - tryme

File Edit Options Buffers Tools Help                                        
Welcome to GNU Emacs, one component of a Linux-based GNU system.
[*** snipped blurb]
----:---F1  *scratch*         (Lisp Interaction)--L1--All----------------------
For information about the GNU Project and its goals, type C-h C-p.

[*** Now type M-x eshell]

File Edit Options Buffers Tools Help
Welcome to the Emacs shell

~ $ cd /usr
/usr $ ls
X11R6  bin  doc  games  include  info  lib  local  sbin  share  src
/usr $ echo $SHELL
/usr/bin/emacs
/usr $ echo $TERM
xterm
/usr $ 

----:---F1  *eshell*          (EShell)--L11--All-------------------------------

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: How to PICK the CTRL-u argument from the file or some other method, with EXAMPLE
  2004-09-23 22:02 ` Jose Cuthberto
  2004-09-23 22:08   ` Chris F.A. Johnson
@ 2004-09-23 23:42   ` Johan Ur Riise
  2004-09-24  7:19   ` Joakim Hove
  2004-09-24 18:46   ` Greg Hill
  3 siblings, 0 replies; 9+ messages in thread
From: Johan Ur Riise @ 2004-09-23 23:42 UTC (permalink / raw)


jose@Aumara.zzn.com (Jose Cuthberto) writes:

> 
> 
> still waiting for a solution

Oh lord - won't you buy me - a mercedes benz..

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: How to  PICK  the CTRL-u argument from the file or some other method, with EXAMPLE
  2004-09-23 22:02 ` Jose Cuthberto
  2004-09-23 22:08   ` Chris F.A. Johnson
  2004-09-23 23:42   ` Johan Ur Riise
@ 2004-09-24  7:19   ` Joakim Hove
  2004-09-24 18:46   ` Greg Hill
  3 siblings, 0 replies; 9+ messages in thread
From: Joakim Hove @ 2004-09-24  7:19 UTC (permalink / raw)



jose@Aumara.zzn.com (Jose Cuthberto) writes:


>>[...] I would want to avoid writing a loops, and vars etc.
Well, if you are willing to relax this requirement you could look into
the functions/forms:

  (string-to-number string)
  (buffer-substring-no-properties p1 p2)
  (dotimes (i max-count) )
  (looking-at REGEXP)
  (match-string match-nr)

and cook something up.

> still waiting for a solution

Now - that's an attitude for getting free support!


-- 
Joakim Hove
hove AT ift uib no
+47 (55 5)8 27 90
http://www.ift.uib.no/~hove/

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: How to PICK the CTRL-u argument from the file or some other  method, with EXAMPLE
  2004-09-23 22:02 ` Jose Cuthberto
                     ` (2 preceding siblings ...)
  2004-09-24  7:19   ` Joakim Hove
@ 2004-09-24 18:46   ` Greg Hill
  2004-09-24 19:12     ` Greg Hill
  3 siblings, 1 reply; 9+ messages in thread
From: Greg Hill @ 2004-09-24 18:46 UTC (permalink / raw)



[-- 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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: How to PICK the CTRL-u argument from the file or some other   method, with EXAMPLE
  2004-09-24 18:46   ` Greg Hill
@ 2004-09-24 19:12     ` Greg Hill
  0 siblings, 0 replies; 9+ messages in thread
From: Greg Hill @ 2004-09-24 19:12 UTC (permalink / raw)



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

At 11:46 AM -0700 9/24/04, Greg Hill wrote:
<snip>
>   (let (from-buf to_buf count line)
</snip>

Oops.  Make that

   (let (from-buf to-buf count line)

--Greg

[-- Attachment #1.2: Type: text/html, Size: 653 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

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2004-09-24 19:12 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2004-09-24 19:12     ` Greg Hill
  -- strict thread matches above, loose matches on Subject: below --
2004-09-23 17:01 JayBingham

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).