* elisp how to insert text at end of each line
@ 2013-04-10 17:28 acomber
2013-04-10 17:36 ` Steven Degutis
` (2 more replies)
0 siblings, 3 replies; 11+ messages in thread
From: acomber @ 2013-04-10 17:28 UTC (permalink / raw)
To: Help-gnu-emacs
I tried:
(while (search-forward "\n")
(insert "My text to insert")
)
and tried using $ symbol.
Neither worked.
Is there a way to do this in elisp?
--
View this message in context: http://emacs.1067599.n5.nabble.com/elisp-how-to-insert-text-at-end-of-each-line-tp283410.html
Sent from the Emacs - Help mailing list archive at Nabble.com.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: elisp how to insert text at end of each line
2013-04-10 17:28 elisp how to insert text at end of each line acomber
@ 2013-04-10 17:36 ` Steven Degutis
2013-04-10 17:39 ` Teemu Likonen
2013-04-10 18:13 ` Thorsten Jolitz
2 siblings, 0 replies; 11+ messages in thread
From: Steven Degutis @ 2013-04-10 17:36 UTC (permalink / raw)
To: acomber; +Cc: help-gnu-emacs@gnu.org
[-- Attachment #1: Type: text/plain, Size: 630 bytes --]
If you want to do it interactively as a user, I would use
multiple-cursors.el (in MELPA,
https://github.com/magnars/multiple-cursors.el/).
Otherwise, don't know.
-Steven
On Wed, Apr 10, 2013 at 12:28 PM, acomber <deedexy@gmail.com> wrote:
> I tried:
>
> (while (search-forward "\n")
> (insert "My text to insert")
> )
>
> and tried using $ symbol.
>
> Neither worked.
>
> Is there a way to do this in elisp?
>
>
>
> --
> View this message in context:
> http://emacs.1067599.n5.nabble.com/elisp-how-to-insert-text-at-end-of-each-line-tp283410.html
> Sent from the Emacs - Help mailing list archive at Nabble.com.
>
>
[-- Attachment #2: Type: text/html, Size: 1265 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: elisp how to insert text at end of each line
2013-04-10 17:28 elisp how to insert text at end of each line acomber
2013-04-10 17:36 ` Steven Degutis
@ 2013-04-10 17:39 ` Teemu Likonen
2013-04-10 17:42 ` Teemu Likonen
2013-04-10 18:13 ` Thorsten Jolitz
2 siblings, 1 reply; 11+ messages in thread
From: Teemu Likonen @ 2013-04-10 17:39 UTC (permalink / raw)
To: acomber; +Cc: Help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 247 bytes --]
acomber [2013-04-10 10:28:29 -07:00] wrote:
> I tried:
>
> (while (search-forward "\n")
> (insert "My text to insert")
> )
Try this instead:
(while (re-search-forward "$" nil t)
(insert "foo")
(goto-char (1+ (point))))
[-- Attachment #2: Type: application/pgp-signature, Size: 835 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: elisp how to insert text at end of each line
2013-04-10 17:28 elisp how to insert text at end of each line acomber
2013-04-10 17:36 ` Steven Degutis
2013-04-10 17:39 ` Teemu Likonen
@ 2013-04-10 18:13 ` Thorsten Jolitz
2013-04-11 10:23 ` acomber
2 siblings, 1 reply; 11+ messages in thread
From: Thorsten Jolitz @ 2013-04-10 18:13 UTC (permalink / raw)
To: help-gnu-emacs
acomber <deedexy@gmail.com> writes:
> I tried:
>
> (while (search-forward "\n")
> (insert "My text to insert")
> )
maybe:
#begin_src emacs-lisp
(defun insert-at-end-of-line (text)
(goto-char (point-min))
(while (not (eobp))
(end-of-line)
(insert text)
(next-line)))
#+end_src
--
cheers,
Thorsten
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: elisp how to insert text at end of each line
2013-04-10 18:13 ` Thorsten Jolitz
@ 2013-04-11 10:23 ` acomber
2013-04-11 10:50 ` Andreas Röhler
` (2 more replies)
0 siblings, 3 replies; 11+ messages in thread
From: acomber @ 2013-04-11 10:23 UTC (permalink / raw)
To: Help-gnu-emacs
That works, thanks. I implemented as a function which inserted literal text.
But I like the idea of being able to pass parameters to the function. so I
tried this:
(defun insert-at-end-of-line (text)
"convert word tbl to html tbl"
(interactive)
(goto-char (point-min))
(while (not (eobp))
(end-of-line)
(insert text)
(next-line)
)
)
But then in emacs how do I pass the text parameter?
I keep getting:
call-interactively: Wrong number of arguments: (lambda (text) "convert word
tbl to html tbl" (interactive) (goto-char (point-min)) (while (not (eobp))
(end-of-line) (insert text) (next-line))), 0
Do I have to specify somewhere that function takes parameters???
--
View this message in context: http://emacs.1067599.n5.nabble.com/elisp-how-to-insert-text-at-end-of-each-line-tp283410p283460.html
Sent from the Emacs - Help mailing list archive at Nabble.com.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: elisp how to insert text at end of each line
2013-04-11 10:23 ` acomber
@ 2013-04-11 10:50 ` Andreas Röhler
2013-04-11 11:01 ` Andreas Röhler
2013-04-11 11:32 ` Thorsten Jolitz
2 siblings, 0 replies; 11+ messages in thread
From: Andreas Röhler @ 2013-04-11 10:50 UTC (permalink / raw)
To: help-gnu-emacs
Am 11.04.2013 12:23, schrieb acomber:
> That works, thanks. I implemented as a function which inserted literal text.
>
> But I like the idea of being able to pass parameters to the function. so I
> tried this:
>
> (defun insert-at-end-of-line (text)
> "convert word tbl to html tbl"
> (interactive)
> (goto-char (point-min))
> (while (not (eobp))
> (end-of-line)
> (insert text)
> (next-line)
> )
> )
>
> But then in emacs how do I pass the text parameter?
>
> I keep getting:
>
> call-interactively: Wrong number of arguments: (lambda (text) "convert word
> tbl to html tbl" (interactive) (goto-char (point-min)) (while (not (eobp))
> (end-of-line) (insert text) (next-line))), 0
>
> Do I have to specify somewhere that function takes parameters???
>
>
>
> --
> View this message in context: http://emacs.1067599.n5.nabble.com/elisp-how-to-insert-text-at-end-of-each-line-tp283410p283460.html
> Sent from the Emacs - Help mailing list archive at Nabble.com.
>
>
that's probably not the best way to do it, just to play on,
fill the text at the (invisible) prompt in the minibuffer
(defun insert-at-end-of-line (text)
"convert word tbl to html tbl"
(interactive "*M")
(goto-char (point-min))
(while (not (eobp))
(end-of-line)
(insert text)
(forward-line 1)))
BTW use forward-line in programs, as next-line is designed for interactive use.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: elisp how to insert text at end of each line
2013-04-11 10:23 ` acomber
2013-04-11 10:50 ` Andreas Röhler
@ 2013-04-11 11:01 ` Andreas Röhler
2013-04-11 11:32 ` Thorsten Jolitz
2 siblings, 0 replies; 11+ messages in thread
From: Andreas Röhler @ 2013-04-11 11:01 UTC (permalink / raw)
To: help-gnu-emacs@gnu.org List
Am 11.04.2013 12:23, schrieb acomber:
> That works, thanks. I implemented as a function which inserted literal text.
>
Interactively just do
M-x query-replace-regexp RET $ RET YOUR-INSERT-TEXT RET
Andreas
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: elisp how to insert text at end of each line
2013-04-11 10:23 ` acomber
2013-04-11 10:50 ` Andreas Röhler
2013-04-11 11:01 ` Andreas Röhler
@ 2013-04-11 11:32 ` Thorsten Jolitz
2013-04-11 14:02 ` acomber
2 siblings, 1 reply; 11+ messages in thread
From: Thorsten Jolitz @ 2013-04-11 11:32 UTC (permalink / raw)
To: help-gnu-emacs
acomber <deedexy@gmail.com> writes:
> (defun insert-at-end-of-line (text)
> "convert word tbl to html tbl"
> (interactive)
> (goto-char (point-min))
> (while (not (eobp))
> (end-of-line)
> (insert text)
> (next-line)
> )
> )
>
> But then in emacs how do I pass the text parameter?
Yes, sorry, I used it with (setq text "hello world") in the scratch
buffer and forgot to account for user input.
--
cheers,
Thorsten
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: elisp how to insert text at end of each line
2013-04-11 11:32 ` Thorsten Jolitz
@ 2013-04-11 14:02 ` acomber
0 siblings, 0 replies; 11+ messages in thread
From: acomber @ 2013-04-11 14:02 UTC (permalink / raw)
To: Help-gnu-emacs
Don't know if its useful but as a result of learning from this forum, I
implemented like this:
(defun do-cols (text)
(goto-char (point-min))
(while (search-forward "\t" nil t)
(replace-match text)
)
)
(defun do-rows (text)
"convert word tbl to html tbl"
(interactive)
(goto-char (point-min))
(while (not (eobp))
(end-of-line)
(insert text)
(forward-line)
)
)
(defun do-table ()
"convert word tbl to html tbl"
(interactive)
(goto-char (point-min))
(insert "
")
(insert "
")
(insert " ")
(do-cols " ")
(do-rows "
")
(insert "")
(insert "")
(insert "
")
)
It’s probably the naffest lisp function ever, but it works for me.
It requires the only text in the buffer to be the table data and only works
on a single table.
--
View this message in context: http://emacs.1067599.n5.nabble.com/elisp-how-to-insert-text-at-end-of-each-line-tp283410p283483.html
Sent from the Emacs - Help mailing list archive at Nabble.com.
^ permalink raw reply [flat|nested] 11+ messages in thread
[parent not found: <mailman.23893.1365614915.855.help-gnu-emacs@gnu.org>]
end of thread, other threads:[~2013-04-11 14:02 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-10 17:28 elisp how to insert text at end of each line acomber
2013-04-10 17:36 ` Steven Degutis
2013-04-10 17:39 ` Teemu Likonen
2013-04-10 17:42 ` Teemu Likonen
2013-04-10 18:13 ` Thorsten Jolitz
2013-04-11 10:23 ` acomber
2013-04-11 10:50 ` Andreas Röhler
2013-04-11 11:01 ` Andreas Röhler
2013-04-11 11:32 ` Thorsten Jolitz
2013-04-11 14:02 ` acomber
[not found] <mailman.23893.1365614915.855.help-gnu-emacs@gnu.org>
2013-04-10 18:07 ` Michael Heerdegen
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.