unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
Cc: emacs-devel@gnu.org, bug-cc-mode@gnu.org, mast@lysator.liu.se
Subject: Re: CC Mode 5.31.3
Date: Sun, 26 Feb 2006 20:39:20 +0000 (GMT)	[thread overview]
Message-ID: <Pine.LNX.3.96.1060226203051.278B-100000@acm.acm> (raw)
In-Reply-To: <E1FDKjU-0000X6-PY@fencepost.gnu.org>

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)




-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642


  parent reply	other threads:[~2006-02-26 20:39 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-02-24 18:13 CC Mode 5.31.3 Alan Mackenzie
2006-02-24 18:51 ` Sean O'Rourke
2006-02-24 22:04   ` Alan Mackenzie
2006-02-26 12:10 ` Richard Stallman
2006-02-26 17:19   ` Alan Mackenzie
2006-02-27 19:01     ` Richard Stallman
2006-02-26 20:39   ` Alan Mackenzie [this message]
2006-02-27  9:07     ` Kim F. Storm
2006-02-27 15:10       ` Alan Mackenzie
2006-02-27 23:46       ` Richard Stallman
2006-02-27 14:31     ` Stefan Monnier
2006-02-27 23:47       ` Richard Stallman
2006-02-27 19:02     ` Richard Stallman
2006-02-26 12:46 ` Vivek Dasmohapatra
     [not found] <87slq8xyqv.fsf-monnier+gmane.emacs.devel@gnu.org>
2006-02-25 11:37 ` Alan Mackenzie
2006-02-26 15:36   ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.3.96.1060226203051.278B-100000@acm.acm \
    --to=acm@muc.de \
    --cc=bug-cc-mode@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=mast@lysator.liu.se \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).