unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* auto-insert-alist
@ 2004-07-14 16:36 DrMemory
  2004-07-14 17:41 ` auto-insert-alist kgold
  2004-07-14 17:56 ` auto-insert-alist Kevin Rodgers
  0 siblings, 2 replies; 9+ messages in thread
From: DrMemory @ 2004-07-14 16:36 UTC (permalink / raw)


I am having some trouble with auto-insertion.

According to the documentation, the "Action" can be a filename, in
which case its contents are to be inserted. However, when I try this,
I get no auto-insertion when I visit a new file:

(setq auto-insert-alist
      (append '(((".*ltr.*\\.tex$" . "Letter") . "~/leg/ltr.tex"))
	      auto-insert-alist))

I changed it to:

(setq auto-insert-alist
      (append '(((".*ltr.*\\.tex$" . "Letter") . 
         (insert-file-contents "~/leg/ltr.tex")))
	      auto-insert-alist))

And now I am prompted for autoinsertion, but the result is just to
have the string "~/leg/ltr.tex" inserted in the new file.

I hope someone can tell me what I am doing wrong...

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

* Re: auto-insert-alist
  2004-07-14 16:36 auto-insert-alist DrMemory
@ 2004-07-14 17:41 ` kgold
  2004-07-14 17:56 ` auto-insert-alist Kevin Rodgers
  1 sibling, 0 replies; 9+ messages in thread
From: kgold @ 2004-07-14 17:41 UTC (permalink / raw)


drmemory@starband.net (DrMemory) writes:
> I am having some trouble with auto-insertion.
> 
> According to the documentation, the "Action" can be a filename, in
> which case its contents are to be inserted. However, when I try this,
> I get no auto-insertion when I visit a new file:
> 
> (setq auto-insert-alist
>       (append '(((".*ltr.*\\.tex$" . "Letter") . "~/leg/ltr.tex"))
> 	      auto-insert-alist))
> 
> I changed it to:
> 
> (setq auto-insert-alist
>       (append '(((".*ltr.*\\.tex$" . "Letter") . 
>          (insert-file-contents "~/leg/ltr.tex")))
> 	      auto-insert-alist))
> 
> And now I am prompted for autoinsertion, but the result is just to
> have the string "~/leg/ltr.tex" inserted in the new file.
> 
> I hope someone can tell me what I am doing wrong...

You can try this until you get a real fix:

(add-hook 'find-file-hooks 'auto-insert)
(setq auto-insert-directory (expand-file-name "~/.autoinsert/"))
(setq auto-insert-query nil)
(define-auto-insert "\\.c\\'"		"autoinsert.c")
(define-auto-insert "\\.cpp\\'"		"autoinsert.c")
(define-auto-insert "\\.java\\'"	"autoinsert.java")
(define-auto-insert "\\.txt\\'"		"autoinsert.txt")

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

* Re: auto-insert-alist
  2004-07-14 16:36 auto-insert-alist DrMemory
  2004-07-14 17:41 ` auto-insert-alist kgold
@ 2004-07-14 17:56 ` Kevin Rodgers
  2004-07-14 19:36   ` auto-insert-alist DrMemory
  1 sibling, 1 reply; 9+ messages in thread
From: Kevin Rodgers @ 2004-07-14 17:56 UTC (permalink / raw)


DrMemory wrote:
 > I am having some trouble with auto-insertion.
 >
 > According to the documentation, the "Action" can be a filename, in
 > which case its contents are to be inserted. However, when I try this,
 > I get no auto-insertion when I visit a new file:
 >
 > (setq auto-insert-alist
 >       (append '(((".*ltr.*\\.tex$" . "Letter") . "~/leg/ltr.tex"))
 > 	      auto-insert-alist))
 >
 > I changed it to:
 >
 > (setq auto-insert-alist
 >       (append '(((".*ltr.*\\.tex$" . "Letter") .
 >          (insert-file-contents "~/leg/ltr.tex")))
 > 	      auto-insert-alist))
 >
 > And now I am prompted for autoinsertion, but the result is just to
 > have the string "~/leg/ltr.tex" inserted in the new file.
 >
 > I hope someone can tell me what I am doing wrong...

Maybe the ~ needs to be explicitly expanded; does this work:

(setq auto-insert-alist
       (cons `((".*ltr.*\\.tex$" . "Letter") . ,(expand-file-name
						"~/leg/ltr.tex"))
	    auto-insert-alist))

-- 
Kevin Rodgers

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

* Re: auto-insert-alist
  2004-07-14 17:56 ` auto-insert-alist Kevin Rodgers
@ 2004-07-14 19:36   ` DrMemory
  2004-07-15 15:54     ` auto-insert-alist Kevin Rodgers
  0 siblings, 1 reply; 9+ messages in thread
From: DrMemory @ 2004-07-14 19:36 UTC (permalink / raw)


On Wed, 14 Jul 2004 11:56:52 -0600, Kevin Rodgers <ihs_4664@yahoo.com> wrote:
>DrMemory wrote:
> > I am having some trouble with auto-insertion.
> >
> > According to the documentation, the "Action" can be a filename, in
> > which case its contents are to be inserted. However, when I try this,
> > I get no auto-insertion when I visit a new file:
> >
> > (setq auto-insert-alist
> >       (append '(((".*ltr.*\\.tex$" . "Letter") . "~/leg/ltr.tex"))
> > 	      auto-insert-alist))
> >
> > I changed it to:
> >
> > (setq auto-insert-alist
> >       (append '(((".*ltr.*\\.tex$" . "Letter") .
> >          (insert-file-contents "~/leg/ltr.tex")))
> > 	      auto-insert-alist))
> >
> > And now I am prompted for autoinsertion, but the result is just to
> > have the string "~/leg/ltr.tex" inserted in the new file.
> >
> > I hope someone can tell me what I am doing wrong...
>
>Maybe the ~ needs to be explicitly expanded; does this work:
>
>(setq auto-insert-alist
>       (cons `((".*ltr.*\\.tex$" . "Letter") . ,(expand-file-name
>						"~/leg/ltr.tex"))
>	    auto-insert-alist))
>

Using expand-file-name does result in being prompted for
auto-insertion; however, what gets inserted is again the file-name
instead of the contents, just as happened when I tried
insert-file-contents! Sigh. I guess I'll have to go back and re-learn
how to write a template. This must be an error in the documentation or
else I'm just not reading it correctly?

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

* Re: auto-insert-alist
  2004-07-14 19:36   ` auto-insert-alist DrMemory
@ 2004-07-15 15:54     ` Kevin Rodgers
  2004-07-15 21:39       ` auto-insert-alist DrMemory
  0 siblings, 1 reply; 9+ messages in thread
From: Kevin Rodgers @ 2004-07-15 15:54 UTC (permalink / raw)


DrMemory wrote:
 > On Wed, 14 Jul 2004 11:56:52 -0600, Kevin Rodgers <ihs_4664@yahoo.com> wrote:
 >>Maybe the ~ needs to be explicitly expanded; does this work:
 >>
 >>(setq auto-insert-alist
 >>      (cons `((".*ltr.*\\.tex$" . "Letter") . ,(expand-file-name
 >> 
					"~/leg/ltr.tex"))
 >>	    auto-insert-alist))
 >
 > Using expand-file-name does result in being prompted for
 > auto-insertion; however, what gets inserted is again the file-name
 > instead of the contents, just as happened when I tried
 > insert-file-contents! Sigh. I guess I'll have to go back and re-learn
 > how to write a template. This must be an error in the documentation or
 > else I'm just not reading it correctly?

I think it is a bug.  The documentation is very clear:

|   A list specifying text to insert by default into a new file.
| Elements look like (CONDITION . ACTION) or ((CONDITION . DESCRIPTION) . ACTION).
| CONDITION maybe a regexp that must match the new file's name, or it may be
| a symbol that must match the major mode for this element to apply.
| Only the first matching element is effective.
| Optional DESCRIPTION is a string for filling `auto-insert-prompt'.
| ACTION may be a skeleton to insert (see `skeleton-insert'), an absolute
| file-name or one relative to `auto-insert-directory' or a function to call.
| ACTION may also be a vector containing several successive single actions as
| described above, e.g. ["header.insert" date-and-author-update].

And the default value includes elements like:

	("[Mm]akefile\\'" . "makefile.inc")

which should be equivalent to:

	(("[Mm]akefile\\'" . "make rule file") . "makefile.inc")

-- 
Kevin Rodgers

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

* Re: auto-insert-alist
  2004-07-15 15:54     ` auto-insert-alist Kevin Rodgers
@ 2004-07-15 21:39       ` DrMemory
  2004-07-15 23:38         ` auto-insert-alist Kevin Rodgers
  0 siblings, 1 reply; 9+ messages in thread
From: DrMemory @ 2004-07-15 21:39 UTC (permalink / raw)


On Thu, 15 Jul 2004 09:54:11 -0600, Kevin Rodgers <ihs_4664@yahoo.com> wrote:
>
>I think it is a bug.  The documentation is very clear:
>
>|   A list specifying text to insert by default into a new file.
>| Elements look like (CONDITION . ACTION) or ((CONDITION . DESCRIPTION) . ACTION).
>| CONDITION maybe a regexp that must match the new file's name, or it may be
>| a symbol that must match the major mode for this element to apply.
>| Only the first matching element is effective.
>| Optional DESCRIPTION is a string for filling `auto-insert-prompt'.
>| ACTION may be a skeleton to insert (see `skeleton-insert'), an absolute
>| file-name or one relative to `auto-insert-directory' or a function to call.
>| ACTION may also be a vector containing several successive single actions as
>| described above, e.g. ["header.insert" date-and-author-update].
>

I'm sort of an elisp novice, but this seems to be the relevant code
from autoinsert.el:

	 ;; Now, if we found something, do it
	 (and action
	      (if (stringp action)
		  (file-readable-p (concat auto-insert-directory action))
		t)
	      (if auto-insert-query
		  (or (if (eq auto-insert-query 'function)
			  (eq this-command 'auto-insert))
		      (y-or-n-p (format auto-insert-prompt desc)))
		t)
	      (mapcar
	       (lambda (action)
		 (if (stringp action)
		     (if (file-readable-p
			  (setq action (concat auto-insert-directory action)))
			 (insert-file-contents action))
		[...]

Looks to me as if the "absolute filename" option is illusory, and any file
to be inserted would have to be given relative to auto-insert-directory.

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

* Re: auto-insert-alist
  2004-07-15 21:39       ` auto-insert-alist DrMemory
@ 2004-07-15 23:38         ` Kevin Rodgers
  2004-07-16 21:01           ` auto-insert-alist DrMemory
  0 siblings, 1 reply; 9+ messages in thread
From: Kevin Rodgers @ 2004-07-15 23:38 UTC (permalink / raw)


DrMemory wrote:
 > I'm sort of an elisp novice, but this seems to be the relevant code
 > from autoinsert.el:
 >
 > 	 ;; Now, if we found something, do it
 > 	 (and action
 > 	      (if (stringp action)
 > 		  (file-readable-p (concat auto-insert-directory action))
 > 		t)
 > 	      (if auto-insert-query
 > 		  (or (if (eq auto-insert-query 'function)
 > 			  (eq this-command 'auto-insert))
 > 		      (y-or-n-p (format auto-insert-prompt desc)))
 > 		t)
 > 	      (mapcar
 > 	       (lambda (action)
 > 		 (if (stringp action)
 > 		     (if (file-readable-p
 > 			  (setq action (concat auto-insert-directory action)))
 > 			 (insert-file-contents action))
 > 		[...]
 >
 > Looks to me as if the "absolute filename" option is illusory, and any file
 > to be inserted would have to be given relative to auto-insert-directory.

Yep: in both cases (concat auto-insert-directory action) should be
(expand-file-name action auto-insert-directory).

-- 
Kevin Rodgers

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

* Re: auto-insert-alist
  2004-07-15 23:38         ` auto-insert-alist Kevin Rodgers
@ 2004-07-16 21:01           ` DrMemory
  2004-07-16 21:55             ` auto-insert-alist Kevin Rodgers
  0 siblings, 1 reply; 9+ messages in thread
From: DrMemory @ 2004-07-16 21:01 UTC (permalink / raw)


On Thu, 15 Jul 2004 17:38:34 -0600, Kevin Rodgers <ihs_4664@yahoo.com> wrote:
>Yep: in both cases (concat auto-insert-directory action) should be
>(expand-file-name action auto-insert-directory).

Ahhh! Perfect. Now the question: Does tracking down such a bug on this
discussion list result in its eventual correction, or should someone
"notify the proper authorities"? (Or round up the usual suspects....?)

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

* Re: auto-insert-alist
  2004-07-16 21:01           ` auto-insert-alist DrMemory
@ 2004-07-16 21:55             ` Kevin Rodgers
  0 siblings, 0 replies; 9+ messages in thread
From: Kevin Rodgers @ 2004-07-16 21:55 UTC (permalink / raw)


DrMemory wrote:
 > On Thu, 15 Jul 2004 17:38:34 -0600, Kevin Rodgers <ihs_4664@yahoo.com> wrote:
 >>Yep: in both cases (concat auto-insert-directory action) should be
 >>(expand-file-name action auto-insert-directory).
 >
 > Ahhh! Perfect. Now the question: Does tracking down such a bug on this
 > discussion list result in its eventual correction, or should someone
 > "notify the proper authorities"? (Or round up the usual suspects....?)

I think bugs and fixes should be reported via M-x report-emacs-bug.

Unfortunately, the patch I submitted got corrupted, but the subject is
self-explanatory:

http://lists.gnu.org/archive/html/bug-gnu-emacs/2004-07/msg00090.html
http://www.google.com/groups?selm=mailman.978.1089828750.22971.bug-gnu-emacs%40gnu.org

-- 
Kevin Rodgers

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

end of thread, other threads:[~2004-07-16 21:55 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-07-14 16:36 auto-insert-alist DrMemory
2004-07-14 17:41 ` auto-insert-alist kgold
2004-07-14 17:56 ` auto-insert-alist Kevin Rodgers
2004-07-14 19:36   ` auto-insert-alist DrMemory
2004-07-15 15:54     ` auto-insert-alist Kevin Rodgers
2004-07-15 21:39       ` auto-insert-alist DrMemory
2004-07-15 23:38         ` auto-insert-alist Kevin Rodgers
2004-07-16 21:01           ` auto-insert-alist DrMemory
2004-07-16 21:55             ` auto-insert-alist Kevin Rodgers

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