emacs-wiki-discuss
[Top][All Lists]
Advanced

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

[emacs-wiki-discuss] (Repost) Switching projects


From: chris
Subject: [emacs-wiki-discuss] (Repost) Switching projects
Date: Fri, 23 Jul 2004 04:05:55 -1000
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (berkeley-unix)

(This is my 3rd or 4th attempt on this - it turns out that someone in my
DSL IP address range must be a spammer - my mail service silently
stopped doing anything with mail - didn't even refuse it.  If one did
get through, please disregard.)

Sacha Chua wrote:

>emacs-wiki-project is a temporary variable used in let-bindings to
>force a project value in a buffer. It should only be set in let-bindings.
>Example:
>
>(let ((emacs-wiki-project planner-project))
>  (planner-mode))
>

Okeydokey.  And so it would appear, in the  (new to me) stable code, 
except for one place - in function emacs-wiki-mode, immediately after 
the docstring.

I imagine variable emacs-wiki-project is defined at the top-level to 
handle the case of someone doing, say, M-x emacs-wiki-mode in a random 
buffer? Or is there another reason for the top-level emacs-wiki-project 
variable, though it doesn't seem to referenced elsewhere?

FTR, I'm just being curious here, it seems very clear that you are aware 
of all this and have given it more than a little thought. :)

In my no doubt very naive view, perhaps something like:

(define-derived-mode emacs-wiki-mode text-mode "Wiki"
  "Quite the decent doc string"
 (emacs-wiki-change-project 
  (if (and (boundp emacs-wiki-project) emacs-wiki-project)
       emacs-wiki-project
    emacs-wiki-default-project)))

would allow for handling that case?  Since emacs-wiki-default-project
is defcustom'ed and bound to a reasonable value when emacs-wiki.el is
loaded, and thus will always be available.

>The following code might not reliably work:
>
>(emacs-wiki-change-project planner-mode)
>(planner-mode)
>
>as the switch to planner-mode zaps local variables.
>

Yah - I just read up a little on that.  Interesting.

According to the docs, as part of the major-mode switch process,
kill-all-local-variables clobbers everything.  I can see why, but it 
is a bit inconvenient in this case, isn't it?

All this maybe explains some of my confusion when I was poking around
while trying to change projects before.

So here is a seriously kludgy idea - what if one were to implement a
top-level 'for internal mode-change use only' alist as a sort of 
mode-change 'stack' and a local mode-change hook that would 'push'
values onto the stack, to be tested and for 'popped' off again when
planner-mode gets control?  And vice-versa, I suppose.

Something like this, maybe?:

(defvar planner-publishing-framework "emacs-wiki")
(defvar planner-mode-change-stack nil)

(defun planner-mode-change-push (vars-to-save)
   (if (boundp 'planner-mode-change-stack)
       (setq planner-mode-change-stack
             (mapcar
              #'(lambda (key)
                  (cons key (symbol-value key)))
              vars-to-save))))

(defun planner-mode-change-pop ()
  (if (and (boundp 'planner-mode-change-stack)
           planner-mode-change-stack)
      (mapc
       #'(lambda (key-val-pair)
           (set (car key-val-pair) (cdr key-val-pair)))
       planner-mode-change-stack)
    (setq planner-mode-change-stack nil)))

;;; Test forms follow
(setq chris-proj "form4s")
(setq xml-docs (list "1" "2" "3"))

;; Something like this might go in the local mode-change hook
(planner-mode-change-push
 (cond
  ((string= planner-publishing-framework "muse")
   (list 'chris-muse-proj 'xml-muse-docs))
  (t (list 'chris-proj 'xml-docs))))

(setq chris-proj nil)
(setq xml-docs nil)
(planner-mode-change-pop)


>This was the cause of the old bug with indexes not being properly
>highlighted and stuff. =)

I think I remember that. :D


-- 
All you need in this life is ignorance and confidence; then success is
sure.
-- Mark Twain (1835 - 1910), Letter to Mrs Foote, Dec. 2, 1887




reply via email to

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