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

* Re: Autoloading of defcustoms etc
  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
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Stallman @ 2005-01-09  3:22 UTC (permalink / raw)
  Cc: abraham, emacs-devel

    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.

This is clearly an improvement, if we don't consider
the bloating that it would cause.  Taking that bloat into account,
perhaps this costs too much.

What is the price?  How much bigger does the Emacs core image get with
this change?


But the cost may be too high.

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

* Re: Autoloading of defcustoms etc
  2005-01-09  3:22 ` Richard Stallman
@ 2005-01-09 21:38   ` Stefan Monnier
  0 siblings, 0 replies; 3+ messages in thread
From: Stefan Monnier @ 2005-01-09 21:38 UTC (permalink / raw)
  Cc: Lennart Borgman, abraham, emacs-devel

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

> This is clearly an improvement, if we don't consider
> the bloating that it would cause.  Taking that bloat into account,
> perhaps this costs too much.

It can also introduce subtle bugs because it could change the time at which
the defcustoms will be executed.

We've lived pretty happily with the current "problem" of not having all vars
available unless you load the corresponding package, so I'd rather postpone
this change to after the next release.


        Stefan

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