Phillip Lord writes:
 > >>>>> "Paul" == Paul Kinnucan <[EMAIL PROTECTED]> writes:
 > 
 >   >> I shall give this a go when I get home tonight.
 >   >>
 >   >> Incidentally I think that there might be a better, if longer term
 >   >> solution.
 >   >>
 >   >> When you start customise from a JDE buffer the customise buffer
 >   >> knows which project you are talking about because it shares the
 >   >> same default-directory as the JDE buffer.
 >   >>
 >   >> So it should be possible to override defcustom to set its
 >   >> variable in a buffer-local variable, and then set all the other
 >   >> buffers in the same project to be the same thing.
 >   >>
 >   >> After all the only reason that project file switch has to happen
 >   >> at all is because defcustom doesn't do buffer-local
 >   >> variables. You could then relegate project files to do what they
 >   >> do best which is serialise the options out so that they get set
 >   >> between sessions (or for newly visited files in an existing
 >   >> project).
 >   >>
 > 
 >   Paul> This sounds like a good idea to me. So the task would be to
 >   Paul> create a defjdeoption macro that does every thing that
 >   Paul> defcustom does and in addition has a "Save in Project" menu
 >   Paul> item that changes the buffer local value of the variable in
 >   Paul> every open project buffer and save the value in the project
 >   Paul> file. If you want to implement this let me know. Otherwise,
 >   Paul> I'll take a stab at it.
 > 
 >  
 > 
 > Paul
 > 
 > I've had a go at implementing the first solution. The second one is a
 > little more wide ranging and I think would have unexpected
 > consequences. For instance using buffer-local variables would mean
 > that you could not disable context switching, which I think you do
 > temporarily during debugging. 
 > 
 > I've attached a "jde-custom.el" file which implements the defjdecustom
 > method. It seems to be working for me at the moment. 

Hi Phil,

I'd like to suggest another approach to this problem. I've implemented
it in my sandbox and it seems to work fine. I'd like to get feedback
from you and others on it. 

The proposed approach is the following.

I have created a new command called jde-customize-option. This command
displays a standard customization buffer with two additional features:
(1) The "Set" menu has a new "Save to Project" option. Selecting this
option sets the option to its customized value, saves the value in the
current project file, and adds the variable to the JDEE's dirty
variable list. (2) The existing "Erase Customization" option now
erases the customization and then deletes the variable from the
current project file. This solution not only eliminates the need for a
defjdeoption macro it also eliminates the need to execute an
additional command to save or delete the variable from the project
file. Accordingly, I propose changing the jde-save-project option
from a command to a function.

How does this strike you?

Paul


 > 
 > It requires two changes to jde.el. I haven't got a current CVS version
 > so I'll send the functions. This is assuming that you have put the
 > changes in that I send the other day....
 > 
 > So...
 > 
 > 
 > I've changed the dirty list variable name, and its declared in jde-custom
 > 
 > (defun jde-set-variables-init-value (&optional msg)
 >   "Set each JDE variable to the value it has at Emacs startup."
 >   (interactive)
 >   (if (or (interactive-p) msg)
 >       (message "Setting JDE variables to startup values..."))
 >   (if jde-customize-dirty-variable-list
 >       (mapcar 
 >        'jde-set-variable-init-value
 >        ;;(jde-symbol-list)
 >        jde-customize-dirty-variable-list
 >        )))
 > 
 > 
 > 
 > 
 > defun jde-set-variables (&rest args)
 >   "Initialize JDE customization variables.  
 > 
 > Takes a variable number of arguments. Each argument 
 > should be of the form:
 > 
 >   (SYMBOL VALUE)
 > 
 > The value of SYMBOL is set to VALUE.
 > "
 >   (while args 
 >     (let ((entry (car args)))
 >       (if (listp entry)
 >        (let* ((symbol (nth 0 entry))
 >               (value (nth 1 entry))
 >               (customized (nth 2 entry))
 >               (set (or (and (local-variable-if-set-p symbol nil) 'set)
 >                        (get symbol 'custom-set)
 >                        'set-default)))
 >          
 >             (add-to-list 'jde-customize-dirty-variable-list symbol)
 >             
 >             (if (or customized
 >                     jde-loaded-project-file-version)
 >                 (put symbol 'customized-value (list value)))
 >             (if jde-loading-project
 >                 (progn
 >                   (jde-log-msg "jde-set-variables: Loading %S from project %s" 
 > symbol
 >                                jde-loading-project)
 >                   (jde-put-project symbol
 >                                    jde-loading-project
 >                                    (eval value)))
 >               (jde-log-msg "jde-set-variables: Loading %S from unknown project" 
 > symbol))
 >             (when (default-boundp symbol)
 >               ;; Something already set this, overwrite it
 >               (funcall set symbol (eval value)))
 >             (setq args (cdr args)))))))
 > 
 > 
 > 
 > 
 > 
 > jde-mode needs this patch...
 > 
 >         ;; Reset the key bindings in case jde-mode-keymap
 >         ;; was not bound at startup.
 >         (let ((jde-customize-skip-dirty t))
 >           (custom-initialize-reset 'jde-key-bindings nil))
 > 
 > or the custom-initialize-reset will force a prompt for save. 
 > 
 > And finally you need to change every instance of "defcustom" to
 > "defjdecustom" EXCEPT for jde-project-name.
 > 
 > 
 > I did this last nigh and haven't fully tested it yet. It will get some
 > use over the next few days from me, but I though earlier would be
 > better than later. 
 > 
 > Cheers
 > 
 > Phil
 > 
 > ;;; jde-custom.el --- Extra custom support for JDE
 > 
 > ;; $Revision: $
 > ;; $Date: $
 > 
 > ;; This file is not part of Emacs
 > 
 > ;; Author: Phillip Lord <[EMAIL PROTECTED]>
 > 
 > ;; Copyright (c) 2004 Phillip Lord
 > 
 > ;; COPYRIGHT NOTICE
 > ;;
 > ;; This program is free software; you can redistribute it and/or modify
 > ;; it under the terms of the GNU General Public License as published by
 > ;; the Free Software Foundation; either version 2, or (at your option)
 > ;; any later version.
 > 
 > ;; This program is distributed in the hope that it will be useful,
 > ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
 > ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 > ;; GNU General Public License for more details.
 > 
 > ;; You should have received a copy of the GNU General Public License
 > ;; along with this program; see the file COPYING.  If not, write to the
 > ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 > ;; Boston, MA 02111-1307, USA.
 > 
 > ;;; Commentary:
 > 
 > ;; This package provides additional custom support for use within JDE.
 > ;; It provides one major entry point, `defjdecustom' which works
 > ;; exactly like `defcustom' except that a) it prompts the user for if
 > ;; they wish to save the project file following re-setting a project
 > ;; file and b) it stores a list of variables that have been set. The
 > ;; main reason for doing this is that it speeds up project file
 > ;; switching significantly.
 > 
 > 
 > ;;; History:
 > ;; 
 > 
 > ;;; Code:
 > (require 'custom)
 > 
 > (defvar jde-customize-dirty-variable-list nil
 >   "A list of variables which have been set.")
 > 
 > (defvar jde-customize-skip-dirty nil
 >   "Should we skip the addition of symbols to the dirty list.
 > Normally you would not want to set this, or it will all go horribly
 > wrong.  Set this to true if you want to avoid the dirty check temporarily.")
 > 
 > (defmacro defjdecustom (symbol value doc &rest args)
 >   "Declare SYMBOL as a customizable variable that defaults to VALUE.
 > DOC is the variable documentation, ARGS the args.
 > 
 > This macro is essentially the same as `defcustom' but adds some small
 > additional functionality"
 >   `(progn
 >      ;; set this variable so we know we are running this macro. If we
 >      ;; don't do this defcustom calls the :set function when eval'd
 >      ;; for a second time. So if you eval a jde lisp buffer all the
 >      ;; variables will be set to dirty. And you get asked a lot of
 >      ;; questions.
 >      (let ((jde-customize-skip-dirty t))
 >        (defcustom ,symbol ,value ,doc ,@args)
 >        (jde-customize-variable-definition ',symbol))))
 > 
 > 
 > (defun jde-customize-variable-definition (symbol)
 >   "Fiddle with SYMBOL properties to appropriately."
 > ;; get the function used to set as set by defcustom
 >   (let ((set-function
 >          (get symbol 'custom-set)))
 >     ;; check we haven't done this already or we will get into a
 >     ;; recursive loop.
 >     (unless
 >         (eq set-function 'jde-customize-set-variable)
 >       ;; store the old setter
 >       (put symbol 'jde-custom-set set-function)
 >       ;; and replace it with our own
 >       (put symbol 'custom-set 'jde-customize-set-variable))))
 > 
 > (defun jde-customize-set-variable(symbol value)
 >   (let ((set-function
 >          (or
 >           (get symbol 'jde-custom-set)
 >           'custom-set-default)))
 >     ;; skip this whole thing if we are eval'ing defjdemacro
 >     (unless jde-customize-skip-dirty
 >       (add-to-list
 >        'jde-customize-dirty-variable-list symbol))
 >     ;; call the set function..
 >     (funcall set-function symbol value)
 >     ;; and ask for save if appropriate
 >     (unless jde-customize-skip-dirty
 >       (if jde-customize-prompt-for-project-save
 >           (jde-customize-prompt-for-save)))))
 > 
 > (defun jde-customize-prompt-for-save()
 >   (if (y-or-n-p "Save project file? ")
 >       (jde-save-project)
 >     (message "")))
 > 
 > ;; These have to go last for obvious reasons
 > (defjdecustom jde-customize-prompt-for-project-save t
 >   "Prompt to save the project file after customising a variable"
 >   :group 'jde
 >   :type 'boolean)
 > 
 > (defjdecustom jde-customize-prompt-function 'y-or-n-p
 >   "Function to query user for project file save"
 >   :group 'jde
 >   :type 'function)
 > 
 > (provide 'jde-custom)
 > 
 > ;;; jde-custom.el ends here
 >  
 > 

Reply via email to