all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Lennart Borgman <lennart.borgman@gmail.com>
Cc: Thomas Lord <lord@emf.net>, emacs-devel <emacs-devel@gnu.org>
Subject: Re: mode setting question
Date: Tue, 14 Jul 2009 20:47:52 -0400	[thread overview]
Message-ID: <jwvmy766agt.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <e01d8a50907141350x6e136da9h1f9075023f001dac@mail.gmail.com> (Lennart Borgman's message of "Tue, 14 Jul 2009 22:50:19 +0200")

>> I would like to set the mode AS IF the visited
>> file name were "hw.c", without that actually being
>> the visited file name.  That 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.
>> 
>> 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))))))




      reply	other threads:[~2009-07-15  0:47 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-14 20:27 mode setting question Thomas Lord
2009-07-14 20:50 ` Lennart Borgman
2009-07-15  0:47   ` Stefan Monnier [this message]

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

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

  git send-email \
    --in-reply-to=jwvmy766agt.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=emacs-devel@gnu.org \
    --cc=lennart.borgman@gmail.com \
    --cc=lord@emf.net \
    /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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.