unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Autoloading of defcustoms etc
@ 2005-01-06 20:10 Lennart Borgman
  2005-01-09  3:22 ` Richard Stallman
  0 siblings, 1 reply; 3+ messages in thread
From: Lennart Borgman @ 2005-01-06 20:10 UTC (permalink / raw)
  Cc: Per Abrahamsen

[-- Attachment #1: Type: text/plain, Size: 997 bytes --]

> It is a generic problem that customize variables are only visible when
> a package is loaded.  It should be fixed, but for all variables, not
> by adding autoloads for individual variables.

Per A wrote this in another thread. I have taken a look at this and got
helpful feedback from Per. My suggestion is that autoload.el autoloads all
defcustom, define-minor-mode, defface and defgroup whether they are marked
for autoloading or not.

I have attached a simple change for generate-file-autoloads that does this.
(Unfortunately this is for Emacs 21.3.1 which is what I am currently using,
but I guess you can get the idea.)

When doing this it may also be important that custom GUI warns before
loading a package. Has this been taking care of already perhaps?

Another important thing is perhaps that the user is warned if customized
variable is saved but will not be used (because it does not require its
package and that package was not loaded when customize accessed the symbol)?

- Lennart

[-- Attachment #2: autoload-fix.el --]
[-- Type: application/octet-stream, Size: 4908 bytes --]

;;; ********* THIS IS FOR EMACS 21.3.1 **************************************
(defun generate-file-autoloads (file)
  "Insert at point a loaddefs autoload section for FILE.
autoloads are generated for defuns and defmacros in FILE
marked by `generate-autoload-cookie' (which see).
If FILE is being visited in a buffer, the contents of the buffer
are used."
  (interactive "fGenerate autoloads for file: ")
  (let ((outbuf (current-buffer))
	(autoloads-done '())
	(load-name (let ((name (file-name-nondirectory file)))
		     (if (string-match "\\.elc?$" name)
			 (substring name 0 (match-beginning 0))
		       name)))
	(print-length nil)
	(print-readably t)		; This does something in Lucid Emacs.
	(float-output-format nil)
	(done-any nil)
	(visited (get-file-buffer file))
	output-end)

    ;; If the autoload section we create here uses an absolute
    ;; pathname for FILE in its header, and then Emacs is installed
    ;; under a different path on another system,
    ;; `update-autoloads-here' won't be able to find the files to be
    ;; autoloaded.  So, if FILE is in the same directory or a
    ;; subdirectory of the current buffer's directory, we'll make it
    ;; relative to the current buffer's directory.
    (setq file (expand-file-name file))
    (let* ((source-truename (file-truename file))
	   (dir-truename (file-name-as-directory
			  (file-truename default-directory)))
	   (len (length dir-truename)))
      (if (and (< len (length source-truename))
	       (string= dir-truename (substring source-truename 0 len)))
	  (setq file (substring source-truename len))))

    (message "Generating autoloads for %s..." file)
    (save-excursion
      (unwind-protect
	  (progn
	    (if visited
		(set-buffer visited)
	      ;; It is faster to avoid visiting the file.
	      (set-buffer (get-buffer-create " *generate-autoload-file*"))
	      (kill-all-local-variables)
	      (erase-buffer)
	      (setq buffer-undo-list t
		    buffer-read-only nil)
	      (emacs-lisp-mode)
	      (insert-file-contents file nil))
	    (save-excursion
	      (save-restriction
		(let ((regexp (regexp-opt 
			       (list
				(regexp-quote "(defcustom ")
				(regexp-quote "(define-minor-mode ")
				(regexp-quote generate-autoload-cookie)
				)
			       )
			      ))
		  (widen)
		  (goto-char (point-min))
		  (while (not (eobp))
		    (skip-chars-forward " \t\n\f")
		    (cond
;;; 		   ((looking-at (regexp-quote generate-autoload-cookie))
;;; 		    (search-forward generate-autoload-cookie)
		     ((looking-at regexp)
		      (if (looking-at (regexp-quote generate-autoload-cookie))
			  (progn
			    (search-forward generate-autoload-cookie)
			    (skip-chars-forward " \t"))
			(while (not (eolp)) (backward-char)))
		      (unless (eolp) (error "not eolp"))
		      (setq done-any t)
		      (if (eolp)
			  ;; Read the next form and make an autoload.
			  (let* ((form (prog1 (read (current-buffer))
					 (or (bolp) (forward-line 1))))
				 (autoload (make-autoload form load-name)))
			    ;;(message "form=%s" (pp-to-string form)) (sleep-for 5)
			    (if autoload
				(setq autoloads-done (cons (nth 1 form)
							   autoloads-done))
			      (setq autoload form))
			    (autoload-print-form autoload))
	 
			;; Copy the rest of the line to the output.
			(princ (buffer-substring
				(progn
				  ;; Back up over whitespace, to preserve it.
				  (skip-chars-backward " \f\t")
				  (if (= (char-after (1+ (point))) ? )
				      ;; Eat one space.
				      (forward-char 1))
				  (point))
				(progn (forward-line 1) (point)))
			       outbuf)))
		     ((looking-at ";")
		      ;; Don't read the comment.
		      (forward-line 1))
		     (t
		      (forward-sexp 1)
		      (forward-line 1))))))))
	(or visited
	    ;; We created this buffer, so we should kill it.
	    (kill-buffer (current-buffer)))
	(set-buffer outbuf)
	(setq output-end (point-marker))))
    (if done-any
	(progn
	  ;; Insert the section-header line
	  ;; which lists the file name and which functions are in it, etc.
	  (insert generate-autoload-section-header)
	  (prin1 (list 'autoloads autoloads-done load-name
		       (autoload-trim-file-name file)
		       (nth 5 (file-attributes file)))
		 outbuf)
	  (terpri outbuf)
	  ;; Break that line at spaces, to avoid very long lines.
	  ;; Make each sub-line into a comment.
	  (with-current-buffer outbuf
	    (save-excursion
	      (forward-line -1)
	      (while (not (eolp))
		(move-to-column 64)
		(skip-chars-forward "^ \n")
		(or (eolp)
		    (insert "\n" generate-autoload-section-continuation)))))
	  (insert ";;; Generated autoloads from "
		  (autoload-trim-file-name file) "\n")
	  (goto-char output-end)
	  (insert generate-autoload-section-trailer)))
    (message "Generating autoloads for %s...done" file)))

[-- Attachment #3: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

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

end of thread, other threads:[~2005-01-09 21:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-01-06 20:10 Autoloading of defcustoms etc Lennart Borgman
2005-01-09  3:22 ` Richard Stallman
2005-01-09 21:38   ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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