[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: CC Mode 5.31.3
From: |
Alan Mackenzie |
Subject: |
Re: CC Mode 5.31.3 |
Date: |
Sun, 26 Feb 2006 20:39:20 +0000 (GMT) |
Hi, Emacs!
On Sun, 26 Feb 2006, Richard Stallman wrote:
> The issues with the Mode Name, and minor mode flags in the mode line are
> still unresolved. On typing M-x smerge-mode, C Mode's flags (the "/la"
> of "C/la") now stay with the major mode, but this is done by setting
> mode-name to "C/la", a stop-gap solution at best.
>Anyway, can't you achieve what you want with a local
>binding for mode-line-modes? Or mode-line-process?
I've now got a solution, almost complete, to the CC Mode submode flags.
It works in Emacs 2[012] and XEmacs 21.4.4. My new functions walk
through mode-line-format, and insert c-submode-flags into whatever
appropriate structure, just after mode-name, making a buffer-local copy
of whatever.
It still needs text properties (help-echo) applying to it. Anyhow, see
what you think of the following:
#########################################################################
(defvar c-submode-indicators "/la"
"The dummy submode indicators for CC Mode")
(or (fboundp 'caddr)
(defun caddr (kons) (car (cdr (cdr kons)))))
(defun c-locate-mode-name (ml-form)
"In ML-FORM, a mode-line construct, locate the variable `mode-name'.
Returns:
\(i) (t . SYMBOL) if SYMBOL is the symbol within ml-form that directly
contains mode-name.
\(ii) The cons whose car is or generates mode-name.
\(iii) t if ml-form is an atom which is mode-name, or an eval: form which
generates it.
\(iv) nil, if we don't find it."
(let (rec-return
(mode-name "Ceci n'est pas un nom de mode."))
(cond
((null ml-form) nil)
((stringp ml-form)
(string= ml-form mode-name))
((symbolp ml-form)
(when (and (boundp ml-form)
(setq rec-return (c-locate-mode-name (symbol-value ml-form))))
(cond
((eq rec-return t) t) ; the symbol is `mode-name'.
((consp rec-return)
(if (eq (car rec-return) t)
rec-return ; a recursively included symbol.
`(t . ,ml-form)))))) ; `mode-name' is directly "in" this symbol.
((consp ml-form)
(cond
((eq (car ml-form) ':eval)
(if (string= mode-name (eval (cadr ml-form)))
t)) ; maybe we should test for string inclusion??
((symbolp (car ml-form))
(if (boundp (car ml-form))
(c-locate-mode-name (if (symbol-value (car ml-form))
(cadr ml-form)
(caddr ml-form)))))
(t
(while
(and ml-form
(not (setq rec-return (c-locate-mode-name (car ml-form))))
(consp (cdr ml-form)))
(setq ml-form (cdr ml-form)))
(if (and ml-form (not rec-return)) ; dotted pair at end of list (XEmacs)
(setq rec-return (c-locate-mode-name (cdr ml-form))))
(if (eq rec-return t)
ml-form
rec-return)))))))
(defun c-copy-tree (kons)
"Make a copy of the list structure, KONS, such that it is completely
distinct from the original list. Don't use on circular lists!"
(if (consp kons)
(cons (c-copy-tree (car kons))
(c-copy-tree (cdr kons)))
kons))
(defun c-splice-submode-indicators ()
(interactive) ; Remove this, eventually. FIXME!!!
(let (target-cons new-link symb)
;; Identify the variable we need to make buffer-local and copy.
(setq target-cons (c-locate-mode-name 'mode-line-format))
(unless (and (consp target-cons)
(eq (car target-cons) t))
(error "c-locate-mode-name, seeking symbol, returned %s" target-cons))
(setq symb (cdr target-cons))
;; Make a buffer local copy of this symbol's value.
(make-local-variable symb)
(set symb (c-copy-tree (symbol-value symb)))
;; Find the cons within this symbol which generates MODE-NAME.
(setq target-cons (c-locate-mode-name (symbol-value symb)))
(if (or (not (consp target-cons))
(eq (car target-cons) t))
(error "c-locate-mode-name, seeking cons, returned %s" target-cons))
;; Splice c-submode-indicators into the list structure.
(setcdr target-cons (cons 'c-submode-indicators (cdr target-cons)))))
#########################################################################
--
Alan Mackenzie (Munich, Germany)