Gnus development mailing list
 help / color / mirror / Atom feed
From: Josh Huber <huber@alum.wpi.edu>
Subject: more file coding info (for XEmacs users)
Date: Thu, 27 Dec 2001 15:59:48 -0500	[thread overview]
Message-ID: <87bsgktm4b.fsf@paradoxical.net> (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



                 reply	other threads:[~2001-12-27 20:59 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=87bsgktm4b.fsf@paradoxical.net \
    --to=huber@alum.wpi.edu \
    /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.
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).