emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Experimental features


From: Stefan Monnier
Subject: Re: Experimental features
Date: Thu, 28 Jun 2007 14:51:29 -0400
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1.50 (gnu/linux)

>     1 - sometimes a single `setq' is not enough to activate a feature.
> That is true, but I don't see that this means we need a special
> framework for these features.

There's no special framework involved.  Just a convention for how to call
the activation function.

>     2 - I like the idea of being able to list the experimental features.
> I think NEWS is good enough for that.

I agree that it's not absolutely important to be able to get
a mechanically-generated list, but it's a good thing.  And since its only
cost is to use a standard naming convention for the activation function, it
seems very much worth it.

> If a feature is a self-contained major mode, and certainly won't affect
> anyone that doesn't enable that mode, that is automatically safe to try
> installing.  So we can just install it with nothing special.

Sure, there are such cases.  E.g. css-mode.  I'm not interested in those
cases here, since we already know how to handle them.

> But if feature involves adding code in some existing files, files
> which have other purposes and uses, that added code might break
> something.  So we might want to add an explicit conditional around
> each piece of code added in other files, so that we KNOW this feature
> can't break anything if you don't enable it.

Or if css-mode did something potentially undesirable in its major-mode
function, in which case enabling it by default for *.css files may not be
desirable either.

A sample patch is attached, which shows the command I'd like to add, the
change to autoload.el to make it more easily accessible, and an example of
how it might be used with vc-bzr.


        Stefan


Index: lisp/emacs-lisp/autoload.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/emacs-lisp/autoload.el,v
retrieving revision 1.126
diff -u -r1.126 autoload.el
--- lisp/emacs-lisp/autoload.el 26 Jun 2007 19:53:11 -0000      1.126
+++ lisp/emacs-lisp/autoload.el 28 Jun 2007 18:49:15 -0000
@@ -305,6 +305,12 @@
   (interactive "fGenerate autoloads for file: ")
   (autoload-generate-file-autoloads file (current-buffer)))
 
+(defvar experimental-feature nil
+  "File-local variable indicating that this package is experimental.
+Experimental packages need to be explicitly activated by calling
+activate-experimental-PACKAGE.")
+(put 'experimental-feature 'safe-local-variable 'booleanp)
+
 ;; When called from `generate-file-autoloads' we should ignore
 ;; `generated-autoload-file' altogether.  When called from
 ;; `update-file-autoloads' we don't know `outbuf'.  And when called from
@@ -409,6 +409,8 @@
                   (forward-line 1))))))
 
           (when output-start
+            (let ((experimental (and (local-variable-p 'experimental-feature)
+                                     experimental-feature)))
             (with-current-buffer outbuf
               (save-excursion
                 ;; Insert the section-header line which lists the file name
@@ -417,8 +419,11 @@
                 (autoload-insert-section-header
                  outbuf autoloads-done load-name relfile
                  (nth 5 (file-attributes relfile)))
-                (insert ";;; Generated autoloads from " relfile "\n"))
-              (insert generate-autoload-section-trailer)))
+                  (insert ";;; Generated autoloads from " relfile "\n")
+                  (when experimental
+                    (insert "(defun activate-experimental-" load-name " 
()\n")))
+                (when experimental (insert ")\n"))
+                (insert generate-autoload-section-trailer))))
           (message "Generating autoloads for %s...done" file))
         (or visited
             ;; We created this buffer, so we should kill it.
Index: lisp/simple.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/simple.el,v
retrieving revision 1.863
diff -u -r1.863 simple.el
--- lisp/simple.el      23 Jun 2007 12:18:52 -0000      1.863
+++ lisp/simple.el      28 Jun 2007 18:49:15 -0000
@@ -5596,6 +5596,30 @@
         buffer-invisibility-spec)
     (setq buffer-invisibility-spec nil)))
 
+
+(defconst activate-experimental-prefix "activate-experimental-")
+(defun activate-experimental-feature (feature)
+  "Activate the feature FEATURE which is considered experimental."
+  (interactive
+   (let ((features
+          (delete "feature"
+                  (mapcar (lambda (str)
+                            (substring
+                             str (length activate-experimental-prefix)))
+                          (all-completions activate-experimental-prefix
+                                           obarray 'fboundp)))))
+     (if (null features)
+         (error "No experimental features in this release")
+       (list (completing-read "Feature: " features)))))
+  (let ((f (intern-soft (concat activate-experimental-prefix
+                                (if (symbolp feature)
+                                    (symbol-name feature)
+                                  feature)))))
+    ;; If the function is not defined, assume this used to be an
+    ;; experimental feature but has now been blessed as a fully supported
+    ;; feature, so there's nothing left to do to activate it.
+    (when (fboundp f) (funcall f))))
+
 ;; Minibuffer prompt stuff.
 
 ;(defun minibuffer-prompt-modification (start end)
Index: lisp/vc-bzr.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/vc-bzr.el,v
retrieving revision 1.7
diff -u -r1.7 vc-bzr.el
--- lisp/vc-bzr.el      28 Jun 2007 02:01:54 -0000      1.7
+++ lisp/vc-bzr.el      28 Jun 2007 18:49:15 -0000
@@ -549,5 +549,10 @@
     (remove-hook 'vc-post-command-functions 'vc-bzr-post-command-function)))
 
 (provide 'vc-bzr)
+
+;; Local Variables:
+;; experimental-feature: t
+;; End:
+
 ;; arch-tag: 8101bad8-4e92-4e7d-85ae-d8e08b4e7c06
 ;;; vc-bzr.el ends here




reply via email to

[Prev in Thread] Current Thread [Next in Thread]