From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Wolfgang Jenkner Newsgroups: gmane.emacs.devel Subject: Re: conf-space-mode Date: Mon, 11 Sep 2006 03:06:32 +0200 Message-ID: References: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1157944086 7990 80.91.229.2 (11 Sep 2006 03:08:06 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 11 Sep 2006 03:08:06 +0000 (UTC) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Sep 11 05:07:59 2006 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1GMc9I-0000fU-UV for ged-emacs-devel@m.gmane.org; Mon, 11 Sep 2006 05:07:53 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GMc9H-0000j4-VS for ged-emacs-devel@m.gmane.org; Sun, 10 Sep 2006 23:07:51 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1GMaGy-0002QF-Fc for emacs-devel@gnu.org; Sun, 10 Sep 2006 21:07:40 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1GMaGr-0002GS-Ao for emacs-devel@gnu.org; Sun, 10 Sep 2006 21:07:40 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GMaGr-0002GJ-7d for emacs-devel@gnu.org; Sun, 10 Sep 2006 21:07:33 -0400 Original-Received: from [62.99.145.2] (helo=mx.inode.at) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1GMaI0-0006wi-TW for emacs-devel@gnu.org; Sun, 10 Sep 2006 21:08:45 -0400 Original-Received: from [62.99.161.78] (port=11003 helo=gaston.none) by smartmx-02.inode.at with esmtp (Exim 4.50) id 1GMaGn-0007BW-Eu for emacs-devel@gnu.org; Mon, 11 Sep 2006 03:07:30 +0200 Original-To: emacs-devel@gnu.org User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux) X-Mailman-Approved-At: Sun, 10 Sep 2006 23:07:38 -0400 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:59652 Archived-At: Richard Stallman writes: > I think I fixed the bug you reported and also got rid of the excess > requests for confirmation. The way you state this suggests that perhaps you forgot that I actually sent a patch? > Would you please test the changes I checked in? You didn't address the problematic use of `current-prefix-arg'. For ease of reference (and since you started a new thread) I include here my original message `patch for conf-space-mode glitches' from Mon, 04 Sep 2006 23:47:56 +0200: Create a file (say, ./x) with the following content: # -*-conf-*- foo bar quux # Local Variables: # conf-space-keywords: "foo" # End: Visit it: C-x C-f x y y There is an inconvenience here, viz. that (by design) you are asked twice about the same Local Variables. Anyway, `foo' has the `font-lock-keyword-face' face text-property now and is correctly highlighted. Now type: C-u C-c SPC n f o o IIUC the result should be the same as above. However `foo' has the `font-lock-variable-name-face' face text-property instead (also, it doesn't make sense to ask about the Local Variables here). On the other hand, C-u C-x C-v n f o o n does give the expected result. However, passing down like this the prefix arg from a different command is quite problematic; for example, `ffap-bindings' rebinds C-x C-f to `find-file-at-point', which also plays tricks with `current-prefix-arg'. In particular, C-u C-x C-f / f t p . f o o . b a r : RET surprises by asking for a "Regexp to match keywords: " (if you have a valid ~/.netrc `ange-ftp-parse-netrc' inserts it in a buffer and calls `normal-mode' etc.) The following patch makes `conf-space-mode' behave like other modes, while still not contradicting what is documented in the docstrings. The disadvantage is that people who put some `conf-space-keywords' dependent function on `conf-space-mode-hook' have to do some more work now; see the comment at the end of the patch below. Index: conf-mode.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/textmodes/conf-mode.el,v retrieving revision 1.14 diff -c -r1.14 conf-mode.el *** conf-mode.el 6 Feb 2006 12:12:26 -0000 1.14 --- conf-mode.el 4 Sep 2006 19:37:58 -0000 *************** *** 190,195 **** --- 190,199 ---- '("^[ \t]*\\([^\000- ]+\\)" 1 'font-lock-variable-name-face))) "Keywords to hilight in Conf Space mode.") + (defvar conf-space-change-flag nil + "Holds what the last call to `conf-space-hack-keywords' returned. + Might be useful if you put more stuff on `hack-local-variables-hook'.") + (defvar conf-colon-font-lock-keywords `(;; [section] (do this first because it may look like a parameter) ("^[ \t]*\\[\\(.+\\)\\]" 1 'font-lock-type-face) *************** *** 467,498 **** (conf-mode-initialize "#" 'conf-space-font-lock-keywords) (set (make-local-variable 'conf-assignment-sign) nil) ! ;; This doesn't seem right, but the next two depend on conf-space-keywords ! ;; being set, while after-change-major-mode-hook might set up imenu, needing ! ;; the following result: ! (hack-local-variables-prop-line) ! (hack-local-variables) ! (cond (current-prefix-arg ! (set (make-local-variable 'conf-space-keywords) ! (if (> (prefix-numeric-value current-prefix-arg) 0) ! (read-string "Regexp to match keywords: ")))) ! (conf-space-keywords) ! (buffer-file-name ! (set (make-local-variable 'conf-space-keywords) ! (assoc-default buffer-file-name conf-space-keywords-alist ! 'string-match)))) ! (set (make-local-variable 'conf-assignment-regexp) ! (if conf-space-keywords ! (concat "\\(?:" conf-space-keywords "\\)[ \t]+.+?\\([ \t]+\\|$\\)") ! ".+?\\([ \t]+\\|$\\)")) ! (setq imenu-generic-expression ! `(,@(cdr imenu-generic-expression) ! ("Parameters" ! ,(if conf-space-keywords ! (concat "^[ \t]*\\(?:" conf-space-keywords ! "\\)[ \t]+\\([^ \t\n]+\\)\\(?:[ \t]\\|$\\)") ! "^[ \t]*\\([^ \t\n[]+\\)\\(?:[ \t]\\|$\\)") ! 1)))) ;;;###autoload (define-derived-mode conf-colon-mode conf-unix-mode "Conf[Colon]" --- 471,533 ---- (conf-mode-initialize "#" 'conf-space-font-lock-keywords) (set (make-local-variable 'conf-assignment-sign) nil) ! (let ((arg (and (eq this-command 'conf-space-mode) current-prefix-arg))) ! (cond (arg ! (set (make-local-variable 'conf-space-keywords) ! (if (> (prefix-numeric-value current-prefix-arg) 0) ! (read-string "Regexp to match keywords: ")))) ! (conf-space-keywords) ;A global value. Useful? ! (buffer-file-name ! (set (make-local-variable 'conf-space-keywords) ! (assoc-default buffer-file-name conf-space-keywords-alist ! 'string-match)))) ! (conf-space-hack-keywords t) ! (unless arg ! (add-hook 'hack-local-variables-hook 'conf-space-hack-keywords nil t)))) ! ! ! (defun conf-space-hack-keywords (&optional mode-flag) ! "Initialize or adjust variables depending on `conf-space-keywords'. ! Returns non-nil iff MODE-FLAG is nil and something actually changed." ! (when (or mode-flag (eq major-mode 'conf-space-mode)) ! (let ((regexp (if conf-space-keywords ! (concat "\\(?:" conf-space-keywords ! "\\)[ \t]+.+?\\([ \t]+\\|$\\)") ! ".+?\\([ \t]+\\|$\\)"))) ! (set (make-local-variable 'conf-space-change-flag) ! (when (or mode-flag (not (string= conf-assignment-regexp regexp))) ! (set (make-local-variable 'conf-assignment-regexp) regexp) ! ;; Take care of `(eval ...)' in `conf-space-font-lock-keywords'. ! (when (and font-lock-mode ! (boundp 'font-lock-keywords)) ;see `normal-mode' ! (font-lock-add-keywords nil nil) ! (font-lock-mode 1)) ! (setq imenu-generic-expression ! `(,@(remq (assoc "Parameters" imenu-generic-expression) ! imenu-generic-expression) ! ("Parameters" ! ,(if conf-space-keywords ! (concat "^[ \t]*\\(?:" conf-space-keywords ! "\\)[ \t]+\\([^ \t\n]+\\)\\(?:[ \t]\\|$\\)") ! "^[ \t]*\\([^ \t\n[]+\\)\\(?:[ \t]\\|$\\)") ! 1))) ! (not mode-flag)))))) ! ! ;; A comment in the original `conf-space-mode' states: [...] ! ;; `after-change-major-mode-hook' might set up imenu, needing [some ! ;; stuff depending on `conf-space-keywords']. ! ! ;; The following snippet makes sure 'after-change-major-mode-hook' is ! ;; run at an appropriate time, though I think it would be cleaner to ! ;; run specific functions instead of the whole hook. ! ! ;; (add-hook 'conf-space-mode-hook ! ;; (lambda () ! ;; (add-hook 'hack-local-variables-hook ! ;; (lambda () ! ;; (when conf-space-change-flag ! ;; (run-hooks 'after-change-major-mode-hook))) ;Yuck! ! ;; t t))) ;;;###autoload (define-derived-mode conf-colon-mode conf-unix-mode "Conf[Colon]"