* newbie elisp help ?? @ 2007-08-15 17:27 William Case 2007-08-15 17:48 ` Lennart Borgman (gmail) [not found] ` <46C342F9.8070808@gmail.com> 0 siblings, 2 replies; 11+ messages in thread From: William Case @ 2007-08-15 17:27 UTC (permalink / raw) To: EMACS List Hi; I am trying to write a function that will insert a line of asterisks+ spaces across a buffer (as a section divider). It was started as an exercise and has become an exercise in futility. I am working in the scratch pad using C-j to test the function as it is being built. I have: (insert "* "). It returns "* nil". Obviously I don't want the "nil" to appear. How do I get rid of it? More importantly to me, how do I get the (insert "* ") command to repeat 27 times to give me 54 characters across the buffer? I know how to make a recursive loop, but it seems to me this is a fairly common challenge and there is a probably a function for repetition that I can't find. I suppose I am asking for the programming equivalent of 'C-u n'. 'insert-char' allows for repeating but only one character at a time, not two. Any guidance would be appreciated. -- Regards Bill ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: newbie elisp help ?? 2007-08-15 17:27 newbie elisp help ?? William Case @ 2007-08-15 17:48 ` Lennart Borgman (gmail) 2007-08-15 18:16 ` William Case [not found] ` <46C342F9.8070808@gmail.com> 1 sibling, 1 reply; 11+ messages in thread From: Lennart Borgman (gmail) @ 2007-08-15 17:48 UTC (permalink / raw) To: William Case; +Cc: EMACS List William Case wrote: > Hi; > > I am trying to write a function that will insert a line of asterisks+ > spaces across a buffer (as a section divider). It was started as an > exercise and has become an exercise in futility. > > I am working in the scratch pad using C-j to test the function as it is > being built. I have: (insert "* "). It returns "* nil". Obviously I > don't want the "nil" to appear. How do I get rid of it? > > More importantly to me, how do I get the (insert "* ") command to repeat > 27 times to give me 54 characters across the buffer? I know how to make > a recursive loop, but it seems to me this is a fairly common challenge > and there is a probably a function for repetition that I can't find. > > I suppose I am asking for the programming equivalent of 'C-u n'. > > 'insert-char' allows for repeating but only one character at a time, not > two. > > Any guidance would be appreciated. Try this: M-: (insert (make-string 50 ?*)) ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: newbie elisp help ?? 2007-08-15 17:48 ` Lennart Borgman (gmail) @ 2007-08-15 18:16 ` William Case 2007-08-15 18:24 ` Lennart Borgman (gmail) 0 siblings, 1 reply; 11+ messages in thread From: William Case @ 2007-08-15 18:16 UTC (permalink / raw) To: Lennart Borgman (gmail); +Cc: EMACS List Hi Lennart; Thanks for the speedy reply. On Wed, 2007-08-15 at 19:48 +0200, Lennart Borgman (gmail) wrote: > William Case wrote: > > Hi; > > > > I am trying to write a function that will insert a line of asterisks+ > > spaces across a buffer (as a section divider). It was started as an > > exercise and has become an exercise in futility. > > > > I am working in the scratch pad using C-j to test the function as it is > > being built. I have: (insert "* "). It returns "* nil". Obviously I > > don't want the "nil" to appear. How do I get rid of it? > > > > More importantly to me, how do I get the (insert "* ") command to repeat > > 27 times to give me 54 characters across the buffer? I know how to make > > a recursive loop, but it seems to me this is a fairly common challenge > > and there is a probably a function for repetition that I can't find. > > > > I suppose I am asking for the programming equivalent of 'C-u n'. > > > > 'insert-char' allows for repeating but only one character at a time, not > > two. > > > > Any guidance would be appreciated. > > Try this: > > M-: (insert (make-string 50 ?*)) Unfortunately, (make-string 50 ?*) is the single character '*', I was shooting for something that was a repetition of two characters (*SPC) so that my section divider looked like: /* * * * * * * * * * * * * * * * * * * * */ I would begin and end the function with (insert 47). I tried (insert (make-string 5 "* ")) and variations thereof, i.e. with and without quotes and ASCII numbers. -- Regards Bill ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: newbie elisp help ?? 2007-08-15 18:16 ` William Case @ 2007-08-15 18:24 ` Lennart Borgman (gmail) 0 siblings, 0 replies; 11+ messages in thread From: Lennart Borgman (gmail) @ 2007-08-15 18:24 UTC (permalink / raw) To: William Case; +Cc: EMACS List William Case wrote: >> Try this: >> >> M-: (insert (make-string 50 ?*)) > > Unfortunately, (make-string 50 ?*) is the single character '*', I was > shooting for something that was a repetition of two characters (*SPC) so > that my section divider looked like: > > /* * * * * * * * * * * * * * * * * * * * */ > > I would begin and end the function with (insert 47). > > I tried (insert (make-string 5 "* ")) and variations thereof, i.e. with > and without quotes and ASCII numbers. Can this help: (while (< (current-column) 50) (insert "* ")) ^ permalink raw reply [flat|nested] 11+ messages in thread
[parent not found: <46C342F9.8070808@gmail.com>]
* Re: newbie elisp help ?? [not found] ` <46C342F9.8070808@gmail.com> @ 2007-08-15 19:07 ` William Case 0 siblings, 0 replies; 11+ messages in thread From: William Case @ 2007-08-15 19:07 UTC (permalink / raw) To: EMACS List Hi Alexis; BINGO! Worked like a charm. On Wed, 2007-08-15 at 20:16 +0200, Alexis Roda wrote: > En/na William Case ha escrit: > > Hi; > > > > I am working in the scratch pad using C-j to test the function as it is > > being built. I have: (insert "* "). It returns "* nil". Obviously I > > don't want the "nil" to appear. How do I get rid of it? > > the insert function inserts "*" and returns nil. You call it by its side > effects, so you can safely ignore the return value (it will not be > inserted). > > > More importantly to me, how do I get the (insert "* ") command to repeat > > 27 times to give me 54 characters across the buffer? I know how to make > > a recursive loop, but it seems to me this is a fairly common challenge > > and there is a probably a function for repetition that I can't find. > > Probably there's a better way: > > (dotimes (some_var 27) (insert "* ")) Tried dotimes early on. Couldn't get it to work so I moved on. I don't remember what I did exactly, that was hours ago, but your suggestion sure works. Thanks. -- Regards Bill ^ permalink raw reply [flat|nested] 11+ messages in thread
[parent not found: <mailman.4824.1187198869.32220.help-gnu-emacs@gnu.org>]
* Re: newbie elisp help ?? [not found] <mailman.4824.1187198869.32220.help-gnu-emacs@gnu.org> @ 2007-08-15 18:02 ` Pascal Bourguignon 2007-08-15 19:04 ` William Case 2007-08-17 20:44 ` Thien-Thi Nguyen 2007-08-15 20:08 ` Joel J. Adamson 1 sibling, 2 replies; 11+ messages in thread From: Pascal Bourguignon @ 2007-08-15 18:02 UTC (permalink / raw) To: help-gnu-emacs William Case <billlinux@rogers.com> writes: > Hi; > > I am trying to write a function that will insert a line of asterisks+ > spaces across a buffer (as a section divider). It was started as an > exercise and has become an exercise in futility. > > I am working in the scratch pad using C-j to test the function as it is > being built. I have: (insert "* "). It returns "* nil". Wrong. (insert "* ") returns just nil, whose textual representation is inserted by the command bound to C-j. > Obviously I > don't want the "nil" to appear. How do I get rid of it? I don't know what command you have bound to C-j. I use C-x C-e and C-u C-x C-e to execute forms. Without C-u, it doesn't print (insert the textual representation of) the result of the form. > More importantly to me, how do I get the (insert "* ") command to repeat > 27 times to give me 54 characters across the buffer? Writting a loop! (require 'cl) C-x C-e (loop repeat 27 do (insert "* ")) C-x C-e inserts: * * * * * * * * * * * * * * * * * * * * * * * * * * * > I know how to make > a recursive loop, but it seems to me this is a fairly common challenge > and there is a probably a function for repetition that I can't find. How do I make a static mobile? How do I make a red blue? > I suppose I am asking for the programming equivalent of 'C-u n'. I suppose you could read some programming tutorial. Wouldn't that be a good idea? What about googling for: emacs lisp tutorial -- __Pascal Bourguignon__ http://www.informatimago.com/ NOTE: The most fundamental particles in this product are held together by a "gluing" force about which little is currently known and whose adhesive power can therefore not be permanently guaranteed. ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: newbie elisp help ?? 2007-08-15 18:02 ` Pascal Bourguignon @ 2007-08-15 19:04 ` William Case 2007-08-17 20:44 ` Thien-Thi Nguyen 1 sibling, 0 replies; 11+ messages in thread From: William Case @ 2007-08-15 19:04 UTC (permalink / raw) To: Pascal Bourguignon; +Cc: help-gnu-emacs Hi Pascal; On Wed, 2007-08-15 at 20:02 +0200, Pascal Bourguignon wrote: > William Case <billlinux@rogers.com> writes: > > > Hi; > > I suppose you could read some programming tutorial. Wouldn't that be a good idea? It is. I did. > What about googling for: emacs lisp tutorial Got it. Did it several months ago. But, I didn't help on this occasion. Seems that I screwed up my use of dotimes somehow. Works now, thanks to advice from Alexis Roda. -- Regards Bill ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: newbie elisp help ?? 2007-08-15 18:02 ` Pascal Bourguignon 2007-08-15 19:04 ` William Case @ 2007-08-17 20:44 ` Thien-Thi Nguyen 1 sibling, 0 replies; 11+ messages in thread From: Thien-Thi Nguyen @ 2007-08-17 20:44 UTC (permalink / raw) To: help-gnu-emacs () Pascal Bourguignon <pjb@informatimago.com> () Wed, 15 Aug 2007 20:02:52 +0200 How do I make a static mobile? How do I make a red blue? when the emacs stops bucking to gyre, perchance its wee lacks give in to desire. dropping from nine-tenths to point-oh-oh-one c, motion and time rent disjoint summarily. w/ space and stars now paired, three to the third (not squared), what good a mention read but not grokked? how could such tension be undone and unlocked? look! the emacs leaves. look! the wee lacks grieve. thi http://www.gnuvola.org/software/personal-elisp/dist/lisp/diversions/yo.el ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: newbie elisp help ?? [not found] <mailman.4824.1187198869.32220.help-gnu-emacs@gnu.org> 2007-08-15 18:02 ` Pascal Bourguignon @ 2007-08-15 20:08 ` Joel J. Adamson 2007-08-16 2:30 ` William Case [not found] ` <mailman.4845.1187231410.32220.help-gnu-emacs@gnu.org> 1 sibling, 2 replies; 11+ messages in thread From: Joel J. Adamson @ 2007-08-15 20:08 UTC (permalink / raw) To: help-gnu-emacs William Case <billlinux@rogers.com> writes: > I suppose I am asking for the programming equivalent of 'C-u n'. Well yeah: my question is "why do you want to program this?" Whenever I want such a divider, I just enter "M-7 M-0 *", like this: ********************************************************************** That took three keystrokes. If you want to repeat it a bunch of times, you can make it a macro, and name the macro. However, either making it a macro and calling it by name, or programming it as an interactive function takes more keystrokes (unless you give it a one-letter name or bind it to a key, e.g., C-c *). If you want to call this from inside a function, or make it part of a mode, I'd suggest looking at the code for major modes, such as sh-mode or message-mode. Joel -- Joel J. Adamson Biostatistician Pediatric Psychopharmacology Research Unit Massachusetts General Hospital Boston, MA 02114 (617) 643-1432 (303) 880-3109 "It can be interesting to study ancient philosophy, but more as a kind of accident report than to teach you anything useful." --Paul Graham http://www.paulgraham.com/raq.html ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: newbie elisp help ?? 2007-08-15 20:08 ` Joel J. Adamson @ 2007-08-16 2:30 ` William Case [not found] ` <mailman.4845.1187231410.32220.help-gnu-emacs@gnu.org> 1 sibling, 0 replies; 11+ messages in thread From: William Case @ 2007-08-16 2:30 UTC (permalink / raw) To: Joel J. Adamson; +Cc: help-gnu-emacs Thanks for your comments Joel; On Wed, 2007-08-15 at 16:08 -0400, Joel J. Adamson wrote: > William Case <billlinux@rogers.com> writes: > > > I suppose I am asking for the programming equivalent of 'C-u n'. > > Well yeah: my question is "why do you want to program this?" Whenever > I want such a divider, I just enter "M-7 M-0 *", like this: > > ********************************************************************** > > That took three keystrokes. If you want to repeat it a bunch of > times, you can make it a macro, and name the macro. However, either > making it a macro and calling it by name, or programming it as an > interactive function takes more keystrokes (unless you give it a > one-letter name or bind it to a key, e.g., C-c *). > > If you want to call this from inside a function, or make it part of a > mode, I'd suggest looking at the code for major modes, such as sh-mode > or message-mode. To respond to your curiosity, I want to build a function that inserts lines as I have described for several reasons. 1. I called it a section a divider in my posts because there are file header programs in the emacs wiki and elsewhere. They are all too big and complex for what I need. They are more suited to a professional programmer who is building a major project with the expectation that those files will be widely distributed. Perhaps, one day I will need something like that. For now, I wanted to avoid debate and just create a simple header for files that are tantamount to practise or sample files, using 'C', elisp or bash. File name, Purpose of program, Author's name, programming date will do for me. 2. I have tried to use something like you suggest, but find the use of a solid line of characters too dense, drawing attention away from the actual programming, and, thus would like to alternate character with a space. 3. It seemed like building a function and sub-functions, was a good self-imposed exercise to practise some of the lisp I had picked up in the tutorial. 4. I wanted to avoid the need for variable arguments, parameters and hooks by writing a simple set of functions where I could copy and manually substitute ';' and '#' for '/* */' commenting out symbols. Hooks, buffer/file names, etc. might come later. 5. I did not ask for advice on the emacs mailing list lightly. I did my due diligence with manuals, info, wiki, archives, google and trial and error. I thought that after several hours of frustration it would be appropriate to ask for guidance. My understanding was that this emacs mailing list is for beginners and experienced people alike. -- Regards Bill, Emacs 22.0.990.1 Fedora 7 ^ permalink raw reply [flat|nested] 11+ messages in thread
[parent not found: <mailman.4845.1187231410.32220.help-gnu-emacs@gnu.org>]
* Re: newbie elisp help ?? [not found] ` <mailman.4845.1187231410.32220.help-gnu-emacs@gnu.org> @ 2007-08-16 14:09 ` Joel J. Adamson 0 siblings, 0 replies; 11+ messages in thread From: Joel J. Adamson @ 2007-08-16 14:09 UTC (permalink / raw) To: help-gnu-emacs William Case <billlinux@rogers.com> writes: > 4. I wanted to avoid the need for variable arguments, parameters > and hooks by writing a simple set of functions where I could > copy and manually substitute ';' and '#' for '/* */' commenting > out symbols. Hooks, buffer/file names, etc. might come later. I understand completely all your desires to learn: I'm doing the same thing myself. To accomplish 4, I suggest checking out ESS, which is a set of major modes for various statistical applications. It's mostly aimed at R, however I use it for Stata; it has all the different comment syntaxes worked out. I've only recently discovered the sh-mode has the ability to stick in complete templates for whiles, fors and conditionals --- it's pretty cool. > 5. I did not ask for advice on the emacs mailing list lightly. I > did my due diligence with manuals, info, wiki, archives, google > and trial and error. I thought that after several hours of > frustration it would be appropriate to ask for guidance. > > My understanding was that this emacs mailing list is for beginners and > experienced people alike. No problem: your post just reminded me of all the times I've thought of doing similar things and discovered that (a) Emacs already does what I want or (b) there's a much simpler way to do it that does not involve any Lisp. This is somewhat of a shame, since I am always trying to find a reason to learn more Lisp (right now I'm studying Scheme more than Emacs Lisp). Unfortunately much of the time Emacs already does what I want and I have no reason to learn: DAMN YOU EMACS LISP DEVELOPERS AND YOUR EXCELLENT PRODUCTS AND EXTENSIONS! YOU'RE RUINING IT FOR THE REST OF US! Have a nice day, Joel -- Joel J. Adamson Biostatistician Pediatric Psychopharmacology Research Unit Massachusetts General Hospital Boston, MA 02114 (617) 643-1432 (303) 880-3109 "It can be interesting to study ancient philosophy, but more as a kind of accident report than to teach you anything useful." --Paul Graham http://www.paulgraham.com/raq.html ^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2007-08-17 20:44 UTC | newest] Thread overview: 11+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2007-08-15 17:27 newbie elisp help ?? William Case 2007-08-15 17:48 ` Lennart Borgman (gmail) 2007-08-15 18:16 ` William Case 2007-08-15 18:24 ` Lennart Borgman (gmail) [not found] ` <46C342F9.8070808@gmail.com> 2007-08-15 19:07 ` William Case [not found] <mailman.4824.1187198869.32220.help-gnu-emacs@gnu.org> 2007-08-15 18:02 ` Pascal Bourguignon 2007-08-15 19:04 ` William Case 2007-08-17 20:44 ` Thien-Thi Nguyen 2007-08-15 20:08 ` Joel J. Adamson 2007-08-16 2:30 ` William Case [not found] ` <mailman.4845.1187231410.32220.help-gnu-emacs@gnu.org> 2007-08-16 14:09 ` Joel J. Adamson
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).