all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* elisp question
@ 2005-11-30 23:13 Tim McNamara
  2005-11-30 23:22 ` Lennart Borgman
                   ` (3 more replies)
  0 siblings, 4 replies; 33+ messages in thread
From: Tim McNamara @ 2005-11-30 23:13 UTC (permalink / raw)


I am looking to write a small program for Emacs which will create a
new buffer and read a randomly selected text file into it after
launching Emacs- rather like yow or fortune, except the files would be
Dharma snippets.  I have a very little experience with programmming
back in college and some with elisp since using Emacs, but it's
limited and so I'm stretching myself to figure this out.  Kind of fun,
actually, and it seems like a high level language like elisp ought to
make it fairly simple.

Creating the buffer works:

(add-hook 'after-init-hook
      (function
       (lambda ()
         (pop-to-buffer (get-buffer-create " *Dharma*"))

After this, I'm having trouble figuring out how to randomly select a
file in a directory and to read the file into the buffer.  

The files are in a subdirectory (called kaya), numbered 1 to whatever,
so I want to randomly pick an integer from 1 to whatever.  I thought
that (find-file) or perhaps (find-file-noselect) could be used in
conjunction with (random), but I can't figure out how to do that.
I've probably missed someting really bloody obvious in the elisp
manual...

Seems to me that there are two steps.  One is to count how many files
are in the directory, and to use that count as the limit for
(random).  Then to take the "random" number generated by (random) and
use it with find-file.

Pointers to relevant information are much appreciated!  I am probably
not even starting in the right place.

^ permalink raw reply	[flat|nested] 33+ messages in thread
* Elisp Question...
@ 2009-09-27 14:32 magicus
  2009-09-27 15:26 ` Giorgos Keramidas
  0 siblings, 1 reply; 33+ messages in thread
From: magicus @ 2009-09-27 14:32 UTC (permalink / raw)
  To: help-gnu-emacs

Hi,

I posted this to comp.emacs when this might be a more useful newgroup.

I am new to using elisp and I put together the following due to ignorance
about how to do it in one function:

==================================================================== (fset
'flp-cr
   "Copyright © 2009 Furlan Lawrence Primus. All rights reserved.")

(global-set-key (kbd "<f9>") 'flp-cr)


(fset 'flp-copyright
   [f9 home ?\C-  ?\C-e ?\M-w])

(global-set-key (kbd "<f8>") 'flp-copyright)
====================================================================

The main point here is that I wanted to be able to have it such that when
I press F8 it displays the text AND copys it so that I can then use it
outside of Emacs. The above seems to work and I'd like to make it a lot
more compact. In addition, while it works in version 22.2.1 it stops after
printing "Copyright" in version GNU Emacs 23.1.50.24 (i686-pc-linux- gnu,
GTK+ Version 2.16.1) of 2009-09-27 on magicbox which I compile earlier
from CVS.

The error message post was:

After 0 kbd macro iterations: up-list: Scan error: "Unbalanced
parentheses", 202, 202

TIA for any comments and suggestions.

ciao,
f

-- 
We are here to laugh at the odds and live our lives so well that Death 
will tremble to take us.
-- Charles Bukowski


^ permalink raw reply	[flat|nested] 33+ messages in thread
[parent not found: <mailman.941.1223918781.25473.help-gnu-emacs@gnu.org>]
* elisp question
@ 2008-10-13 17:36 Seweryn Kokot
  0 siblings, 0 replies; 33+ messages in thread
From: Seweryn Kokot @ 2008-10-13 17:36 UTC (permalink / raw)
  To: help-gnu-emacs

Hello,

I would like to get a list of functions for keybindings from C-x C-a to
C-x C-z etc.

Since (key-binding (kbd "C-x C-f")) gives find-file

I try to write something like this:

(defun my-list-keybindings ()
  (interactive)
  (let* (keyb
		 (char-a 97)
		 (char-z 122)
		 (n (- char-z char-a)))
	(dotimes (i n)
	  (setq keyb (concat "C-x C-" (char-to-string (+ char-a i))))
	  (key-binding (kbd keyb)))))

but unfortunately it doesn't work because kbd doesn't accept variable
string. How to modify this function to get it work?


Thanks in advance.
-- 
regards,
Seweryn





^ permalink raw reply	[flat|nested] 33+ messages in thread
* elisp question
@ 2008-04-30 21:23 harven
  2008-05-01 13:08 ` Kevin Rodgers
                   ` (2 more replies)
  0 siblings, 3 replies; 33+ messages in thread
From: harven @ 2008-04-30 21:23 UTC (permalink / raw)
  To: help-gnu-emacs

I am trying to device a short command to
interactively resize the current window:

(defun resize-window (key)
 "resize interactively the window"
 (interactive "c- widen, _ shrink")
   (cond
     ((eq key (string-to-char "-"))
        (enlarge-window 1)
        (call-interactively 'resize-window))
     ((eq key (string-to-char "_"))
        (enlarge-window -1)
        (call-interactively 'resize-window))
     (t (insert key))))

I type -/_ a number of times, the window enlarges/shrinks, and if I
type another character, the window resizing stops and the character is
inserted.

However, I would like the following effect.
Any entry other than -/_ should end the resizing and be executed. How
can I achieve such effect ?


^ permalink raw reply	[flat|nested] 33+ messages in thread
* elisp question
@ 2003-08-20  7:37 Mike Ballard
  2003-08-20  8:07 ` Joakim Hove
  2003-08-20 15:07 ` Peter Lee
  0 siblings, 2 replies; 33+ messages in thread
From: Mike Ballard @ 2003-08-20  7:37 UTC (permalink / raw)



Hi - 

I don't know much about elisp but was able to piece together a little
snippet that pretty much does what I want.  And that's to determine if a
post is to Usenet and write a copy to a file.

The problem is if I post again to the same group (w/o restarting Gnus) I
get the mb msg '<file> has changed on disk - really edit the buffer?'  I'd
like to eliminate that (I can post to other groups fine so long as I don't
try more than one post to any group during a single Gnus session).

If there was some way to add code which re-reads the disk file before it's
written to a second time that (apparently) would fix it.  Or there's
probably a better way that I have no idea about.  (The "touch" is in there
in case the file doesn't already exist and I wonder if it's the problem?
I tried using file-exists-p but have sort of been going in circles
(backwards) without success).

Can someone tell me how to alter the code below either by re-reading the
disk file before it's written again or if "touch" is the problem maybe
someone could tell me how to use file-exists-p?  I think I'd still need
the "touch" (or something) for the occasions when the file does not yet
exist.


    (start-process-shell-command "foo" "bar"
	"/bin/touch" (format "/dd/Gnus/posts/%s.posts" group))
    (if (not (message-news-p))
	"nnfolder:../mail/mail_cc"
   (format "nnfolder:../posts/%s.posts" group)))


Mike
-- 

mike.ballard--at--earthlink.net

  "Roses are red, violets are blue,
   I'm schizophrenic and so am I"

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

end of thread, other threads:[~2009-09-27 17:10 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-11-30 23:13 elisp question Tim McNamara
2005-11-30 23:22 ` Lennart Borgman
2005-12-01  5:07 ` Stefan Monnier
2005-12-01 19:29   ` Tim McNamara
2005-12-01 21:00     ` Stefan Monnier
2005-12-02  1:02       ` Tim McNamara
2005-12-02 17:51   ` Kevin Rodgers
2005-12-01  6:24 ` N. Raghavendra
2005-12-01 19:32   ` Tim McNamara
2005-12-01 21:37     ` N. Raghavendra
2005-12-01 23:40       ` Thien-Thi Nguyen
2005-12-02  7:44         ` N. Raghavendra
2005-12-02 14:43           ` Thien-Thi Nguyen
2005-12-02  1:05       ` Tim McNamara
     [not found] ` <mailman.17404.1133392955.20277.help-gnu-emacs@gnu.org>
2005-12-01 19:25   ` Tim McNamara
  -- strict thread matches above, loose matches on Subject: below --
2009-09-27 14:32 Elisp Question magicus
2009-09-27 15:26 ` Giorgos Keramidas
2009-09-27 17:10   ` magicus
     [not found] <mailman.941.1223918781.25473.help-gnu-emacs@gnu.org>
2008-10-13 18:11 ` elisp question Niels Giesen
2008-10-13 19:09   ` Seweryn Kokot
     [not found]   ` <mailman.948.1223924333.25473.help-gnu-emacs@gnu.org>
2008-10-13 19:40     ` Pascal J. Bourguignon
2008-10-13 20:47       ` Drew Adams
2008-10-13 21:11       ` Seweryn Kokot
2008-10-13 17:36 Seweryn Kokot
2008-04-30 21:23 harven
2008-05-01 13:08 ` Kevin Rodgers
     [not found] ` <mailman.11020.1209647315.18990.help-gnu-emacs@gnu.org>
2008-05-01 13:54   ` harven
2008-05-03 15:38 ` Bastien
2003-08-20  7:37 Mike Ballard
2003-08-20  8:07 ` Joakim Hove
2003-08-22  5:52   ` Mike Ballard
2003-08-22  6:38     ` Joakim Hove
2003-08-20 15:07 ` Peter Lee

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.