From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.bugs Subject: bug#39190: 28.0.50; two buffers with same buffer-file-name (diff-syntax-fontify-props) Date: Tue, 18 Feb 2020 18:31:38 -0500 Message-ID: References: <875zh73dg8.fsf@betli.tmit.bme.hu> <8736c921s6.fsf@mail.linkov.net> <875zh13e5d.fsf@mail.linkov.net> <87h80iqafm.fsf@betli.tmit.bme.hu> <87ftg0fnyb.fsf@mail.linkov.net> <87d0b3qz3m.fsf@betli.tmit.bme.hu> <871rrhkgkm.fsf@mail.linkov.net> <87v9os914e.fsf@betli.tmit.bme.hu> <87a764y35u.fsf@mail.linkov.net> <87r1zd8gvx.fsf@betli.tmit.bme.hu> <87imknqogu.fsf@mail.linkov.net> <87lfpi548j.fsf@mail.linkov.net> <87a75wek14.fsf@mail.linkov.net> <87sgjj7njt.fsf@betli.tmit.bme.hu> <87o8twep2f.fsf@mail.linkov.net> <87sgj78q2o.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="64003"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: 39190@debbugs.gnu.org, Felician Nemeth To: Juri Linkov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Feb 19 00:32:18 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1j4CLi-000GVl-4R for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 19 Feb 2020 00:32:18 +0100 Original-Received: from localhost ([::1]:43236 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j4CLg-000117-Tk for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 18 Feb 2020 18:32:16 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:57006) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j4CLU-00010s-Jp for bug-gnu-emacs@gnu.org; Tue, 18 Feb 2020 18:32:05 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j4CLS-000487-RP for bug-gnu-emacs@gnu.org; Tue, 18 Feb 2020 18:32:04 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:35493) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j4CLS-00047l-LE for bug-gnu-emacs@gnu.org; Tue, 18 Feb 2020 18:32:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1j4CLS-00086S-HY for bug-gnu-emacs@gnu.org; Tue, 18 Feb 2020 18:32:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 18 Feb 2020 23:32:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 39190 X-GNU-PR-Package: emacs Original-Received: via spool by 39190-submit@debbugs.gnu.org id=B39190.158206871431134 (code B ref 39190); Tue, 18 Feb 2020 23:32:02 +0000 Original-Received: (at 39190) by debbugs.gnu.org; 18 Feb 2020 23:31:54 +0000 Original-Received: from localhost ([127.0.0.1]:41466 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1j4CLJ-000863-LN for submit@debbugs.gnu.org; Tue, 18 Feb 2020 18:31:54 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:16464) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1j4CLH-00085p-54 for 39190@debbugs.gnu.org; Tue, 18 Feb 2020 18:31:51 -0500 Original-Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 73C8344E719; Tue, 18 Feb 2020 18:31:45 -0500 (EST) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 9B16244E70E; Tue, 18 Feb 2020 18:31:39 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1582068699; bh=YT+WlnZSoQpiefxfZAjHlUYtFPKNOEjohfBwGyG3cRU=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=AskAn7MYM3oyaqAIKmH9M+qG+2o5jZ/5Wu5A/MjJ1g2X5vudVKJhPg04ZEJXvpoaR j3DwVdpAwRDpcR0YOkc5QtXZm53h+XDQLuIjQ+FZ55R2+KcgKnQ8Otx8BJws7s+EVG T3SCc/lg3wYYl28aRnGCjql7PsnnrP8V5c0iGWriToV7N+CGTlSBvQWI/26fLiLzZy TD0tkg2VIw53qzxlIFs7J5ygeMZKOlSo8+ujHRmuq8pzZ/cH9kwPFq5Uoh+FiFxYLo 8FRElwouXw9UgutNI+YLXSfDvVvBLAq2dHaW+O9M6kUsLoJJnYH0a0h46zEgedEfQw 6sCRjSDFigdTw== Original-Received: from pastel (unknown [157.52.14.222]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 2534A1202F3; Tue, 18 Feb 2020 18:31:39 -0500 (EST) In-Reply-To: (Stefan Monnier's message of "Tue, 18 Feb 2020 18:07:02 -0500") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:176229 Archived-At: >> Maybe a simpler variant would be to use some other variable to distinguish >> sub-mode and its parent, instead of relying on delay-mode-hooks? > > That's kinda hard if you want to use define-derived-mode and we do: when > we call `conf-foo-mode` the first things it does is: bind > `delay-mode-hooks` and call the parent (`conf-mode`), so the only > difference between this call to the parent and a direct call to the > generic entry point is the binding of `delay-mode-hooks`. IOW, I think we should start with something like the patch below which makes `conf-guess-mode` available, after which we can start fixing the various callers to call `conf-guess-mode` instead. Stefan diff --git a/lisp/textmodes/conf-mode.el b/lisp/textmodes/conf-mode.el index 86db698043..b3325eeff6 100644 --- a/lisp/textmodes/conf-mode.el +++ b/lisp/textmodes/conf-mode.el @@ -351,7 +351,37 @@ conf-outline-level ;;;###autoload -(defun conf-mode () +(defun conf-guess-mode () + "Enable the conf-*-mode that seems most appropriate." + (let ((unix 0) (win 0) (equal 0) (colon 0) (space 0) (jp 0)) + (save-excursion + (goto-char (point-min)) + (while (not (eobp)) + (skip-chars-forward " \t\f") + (cond ((eq (char-after) ?\#) (setq unix (1+ unix))) + ((eq (char-after) ?\;) (setq win (1+ win))) + ((eq (char-after) ?\[)) ; nop + ((eolp)) ; nop + ((eq (char-after) ?})) ; nop + ;; recognize at most double spaces within names + ((looking-at "[^ \t\n=:]+\\(?: ?[^ \t\n=:]+\\)*[ \t]*[=:]") + (if (eq (char-before (match-end 0)) ?=) + (setq equal (1+ equal)) + (setq colon (1+ colon)))) + ((looking-at "/[/*]") (setq jp (1+ jp))) + ((looking-at ".*{")) ; nop + ((setq space (1+ space)))) + (forward-line))) + (cond + ((> jp (max unix win 3)) (conf-javaprop-mode)) + ((> colon (max equal space)) (conf-colon-mode)) + ((> space (max equal colon)) (conf-space-mode)) + ((or (> win unix) (and (= win unix) (eq system-type 'windows-nt))) + (conf-windows-mode)) + (t (conf-unix-mode))))) + +;;;###autoload +(define-derived-mode conf-mode nil "Conf[?]" "Mode for Unix and Windows Conf files and Java properties. Most conf files know only three kinds of constructs: parameter assignments optionally grouped into sections and comments. Yet @@ -372,7 +402,7 @@ conf-mode quite right. Patches that clearly identify some special case, without breaking the general ones, are welcome. -If instead you start this mode with the generic `conf-mode' +If instead you start this mode with the generic `conf-guess-mode' command, it will parse the buffer. It will generally well identify the first four cases listed below. If the buffer doesn't have enough contents to decide, this is identical to @@ -381,46 +411,13 @@ conf-mode `conf-ppd-mode' and `conf-xdefaults-mode'. \\{conf-mode-map}" - - (interactive) - ;; `conf-mode' plays two roles: it's the parent of several sub-modes - ;; but it's also the function that chooses between those submodes. - ;; To tell the difference between those two cases where the function - ;; might be called, we check `delay-mode-hooks'. - ;; (adopted from tex-mode.el) + ;; `conf-mode' is the parent of several sub-modes but it's also sometimes + ;; abused as the function that chooses between those submodes. They should + ;; call `conf-guess-mode' directly, but for historical reasons, we try to + ;; accommodate those misuses with this ugly hack. (if (not delay-mode-hooks) - ;; try to guess sub-mode of conf-mode based on buffer content - (let ((unix 0) (win 0) (equal 0) (colon 0) (space 0) (jp 0)) - (save-excursion - (goto-char (point-min)) - (while (not (eobp)) - (skip-chars-forward " \t\f") - (cond ((eq (char-after) ?\#) (setq unix (1+ unix))) - ((eq (char-after) ?\;) (setq win (1+ win))) - ((eq (char-after) ?\[)) ; nop - ((eolp)) ; nop - ((eq (char-after) ?})) ; nop - ;; recognize at most double spaces within names - ((looking-at "[^ \t\n=:]+\\(?: ?[^ \t\n=:]+\\)*[ \t]*[=:]") - (if (eq (char-before (match-end 0)) ?=) - (setq equal (1+ equal)) - (setq colon (1+ colon)))) - ((looking-at "/[/*]") (setq jp (1+ jp))) - ((looking-at ".*{")) ; nop - ((setq space (1+ space)))) - (forward-line))) - (cond - ((> jp (max unix win 3)) (conf-javaprop-mode)) - ((> colon (max equal space)) (conf-colon-mode)) - ((> space (max equal colon)) (conf-space-mode)) - ((or (> win unix) (and (= win unix) (eq system-type 'windows-nt))) - (conf-windows-mode)) - (t (conf-unix-mode)))) - - (kill-all-local-variables) - (use-local-map conf-mode-map) - (setq major-mode 'conf-mode - mode-name "Conf[?]") + ;; Try to guess sub-mode of conf-mode based on buffer content. + (conf-guess-mode) (set (make-local-variable 'font-lock-defaults) '(conf-font-lock-keywords nil t nil nil)) ;; Let newcomment.el decide this for itself. @@ -438,8 +435,7 @@ conf-mode ;; [section] (nil "^[ \t]*\\[[ \t]*\\(.+\\)[ \t]*\\]" 1) ;; section { ... } - (nil "^[ \t]*\\([^=:{} \t\n][^=:{}\n]+\\)[ \t\n]*{" 1))) - (run-mode-hooks 'conf-mode-hook))) + (nil "^[ \t]*\\([^=:{} \t\n][^=:{}\n]+\\)[ \t\n]*{" 1))))) (defun conf-mode-initialize (comment &optional font-lock) "Initializations for sub-modes of `conf-mode'.