Gnus development mailing list
 help / color / mirror / Atom feed
* more file coding info (for XEmacs users)
@ 2001-12-27 20:59 Josh Huber
  0 siblings, 0 replies; only message in thread
From: Josh Huber @ 2001-12-27 20:59 UTC (permalink / raw)


It seems as though coding tags inside Local Variables are not
supported, which is unfortunate...especially in the case of files like
ChangeLog which really need this information at the end of the file.

So, here's my workaround:

(defun jmh:find-coding-cookie-in-local-variables (filename visit)
  (with-temp-buffer
    (let* ((attrs (file-attributes filename))
	   (size (nth 7 attrs))
	   (start (- size 3001))
	   (end (1- size)))
      (when (< start 0)	(setq start 0))
      (when (< end 0) (setq end 0))
      ;; check only the last 3000 bytes of the file for the cookie
      (insert-file-contents-literally filename nil start end)
      (save-excursion
	(let (start end prefix postfix)
	  (and (re-search-forward
		;; \ between Local and Variables to make sure
		;; XEmacs doesn't think it's an actual
		;; Local Vars block
		"^\\(.*?\\)[ \t]*Local\ Variables:\\(.*\\)" nil t)
	       (setq prefix (regexp-quote
			     (buffer-substring
			      (match-beginning 1) (match-end 1))))
	       (setq postfix (regexp-quote
			      (buffer-substring
			       (match-beginning 2) (match-end 2))))
	       (setq start (match-end 0))
	       (re-search-forward
		(concat "\n" prefix "[ \t]*End:" postfix))
	       (setq end (match-beginning 0))
	       ;; narrow to the correct region and look for the cookie
	       (save-restriction
		 (narrow-to-region start end)
		 (goto-char start)
		 (re-search-forward
		  (concat "\n" prefix "[ \t]*coding: \\([^\n]+\\)" postfix)
		  nil t))
	       (let ((codesys
		      (intern (buffer-substring
			       (match-beginning 1) (match-end 1)))))
		 (if (find-coding-system codesys) codesys))))))))

(add-hook 'insert-file-contents-pre-hook
	  'jmh:find-coding-cookie-in-local-variables)

ttyl,

-- 
Josh Huber



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2001-12-27 20:59 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-12-27 20:59 more file coding info (for XEmacs users) Josh Huber

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).