* mode setting question
@ 2009-07-14 20:27 Thomas Lord
2009-07-14 20:50 ` Lennart Borgman
0 siblings, 1 reply; 3+ messages in thread
From: Thomas Lord @ 2009-07-14 20:27 UTC (permalink / raw)
To: emacs-devel
I am having some trouble puzzling out how to
properly set the mode of a newly created buffer
in a certain case. The function NORMAL-MODE
doesn't appear to be what I want.
Can someone please give me some guidance for
this case:
My program has created a new buffer with a
strange name. The appropriate mode is not
directly implied by the buffer name.
There is no visited file for this buffer. So
there is no visited file name.
The buffer contents have been initialized by
a CALL-PROCESS application. The contents might
have auto-mode stuff at the top or bottom of the
file.
I have a variable, call it MY-NOMINAL-FILE-NAME
which might be bound to something like "hw.c". There is no
real, local file called "hw.c" but I know that this
new buffer is conceptually open to a file named "hw.c".
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?
An "unclean" way would be to, within an
unwind protect, temporarily set the visited file
name as a fiction, then call NORMAL-MODE, then
eliminate the visited file name. Yet, I fret
that the arbitrary code the mode function runs
might do something "bad" on the false assumption
that temporary visited file name is true.
(If the question is ill-formed, betraying
some deeper misunderstanding, please let me
know that instead.)
Thanks,
-t
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: mode setting question
2009-07-14 20:27 mode setting question Thomas Lord
@ 2009-07-14 20:50 ` Lennart Borgman
2009-07-15 0:47 ` Stefan Monnier
0 siblings, 1 reply; 3+ messages in thread
From: Lennart Borgman @ 2009-07-14 20:50 UTC (permalink / raw)
To: Thomas Lord; +Cc: emacs-devel
On Tue, Jul 14, 2009 at 10:27 PM, Thomas Lord<lord@emf.net> wrote:
>
> 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".
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: mode setting question
2009-07-14 20:50 ` Lennart Borgman
@ 2009-07-15 0:47 ` Stefan Monnier
0 siblings, 0 replies; 3+ messages in thread
From: Stefan Monnier @ 2009-07-15 0:47 UTC (permalink / raw)
To: Lennart Borgman; +Cc: Thomas Lord, emacs-devel
>> 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))))))
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2009-07-15 0:47 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-14 20:27 mode setting question Thomas Lord
2009-07-14 20:50 ` Lennart Borgman
2009-07-15 0:47 ` Stefan Monnier
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.