From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: mode setting question Date: Tue, 14 Jul 2009 20:47:52 -0400 Message-ID: References: <1247603229.5941.25.camel@dell-desktop.example.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1247618890 2414 80.91.229.12 (15 Jul 2009 00:48:10 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 15 Jul 2009 00:48:10 +0000 (UTC) Cc: Thomas Lord , emacs-devel To: Lennart Borgman Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Jul 15 02:48:03 2009 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1MQsfB-0004YU-A9 for ged-emacs-devel@m.gmane.org; Wed, 15 Jul 2009 02:48:01 +0200 Original-Received: from localhost ([127.0.0.1]:48538 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MQsfA-0007Hu-Q9 for ged-emacs-devel@m.gmane.org; Tue, 14 Jul 2009 20:48:00 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MQsf4-0007HE-M0 for emacs-devel@gnu.org; Tue, 14 Jul 2009 20:47:54 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MQsf0-0007Bu-2R for emacs-devel@gnu.org; Tue, 14 Jul 2009 20:47:54 -0400 Original-Received: from [199.232.76.173] (port=37583 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MQsez-0007Bo-Vl for emacs-devel@gnu.org; Tue, 14 Jul 2009 20:47:49 -0400 Original-Received: from ironport2-out.pppoe.ca ([206.248.154.182]:58310 helo=ironport2-out.teksavvy.com) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MQsez-0002O1-LU for emacs-devel@gnu.org; Tue, 14 Jul 2009 20:47:49 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AuYEAJfEXErO+KNz/2dsb2JhbACBUdAxhAgFhm4 X-IronPort-AV: E=Sophos;i="4.42,400,1243828800"; d="scan'208";a="41624540" Original-Received: from 206-248-163-115.dsl.teksavvy.com (HELO pastel.home) ([206.248.163.115]) by ironport2-out.teksavvy.com with ESMTP; 14 Jul 2009 20:47:35 -0400 Original-Received: by pastel.home (Postfix, from userid 20848) id 103677EF7; Tue, 14 Jul 2009 20:47:52 -0400 (EDT) In-Reply-To: (Lennart Borgman's message of "Tue, 14 Jul 2009 22:50:19 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.94 (gnu/linux) X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. 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:112476 Archived-At: >> I would like to set the mode AS IF the visited >> file name were "hw.c", without that actually being >> the visited file name. =A0That is, if the contents >> include automode foo within the buffer, use that. >> If not, consult the auto-mode-alist using hw.c >> and use that. >>=20 >> What is the clean way to do so? > Ask here ;-) > This is a thing I have asked for several times. The code in > normal-mode should be broken up so that it is possible to ask "what > mode is the normal modes for files named nn.ext". Agreed. See below an example of how I hacked around this problem in PCL-CVS. Stefan (defun cvs-retrieve-revision (fileinfo rev) "Retrieve the given REVision of the file in FILEINFO into a new buffer." (let* ((file (cvs-fileinfo->full-name fileinfo)) (buffile (concat file "." rev))) (or (find-buffer-visiting buffile) (with-current-buffer (create-file-buffer buffile) (message "Retrieving revision %s..." rev) ;; Discard stderr output to work around the CVS+SSH+libc ;; problem when stdout and stderr are the same. (let ((res (let ((coding-system-for-read 'binary)) (apply 'process-file cvs-program nil '(t nil) nil "-q" "update" "-p" ;; If `rev' is HEAD, don't pass it at all: ;; the default behavior is to get the head ;; of the current branch whereas "-r HEAD" ;; stupidly gives you the head of the trunk. (append (unless (equal rev "HEAD") (list "-r" rev= )) (list file)))))) (when (and res (not (and (equal 0 res)))) (error "Something went wrong retrieving revision %s: %s" rev res)) ;; Figure out the encoding used and decode the byte-sequence ;; into a sequence of chars. (decode-coding-inserted-region (point-min) (point-max) file t nil nil t) ;; Set buffer-file-coding-system. (after-insert-file-set-coding (buffer-size) t) (set-buffer-modified-p nil) (let ((buffer-file-name (expand-file-name file))) (after-find-file)) (toggle-read-only 1) (message "Retrieving revision %s... Done" rev) (current-buffer))))))