[gnu.emacs] header.el clarifications

lrs@indetech.com (Lynn Slater) (11/10/89)

> When a new header is created in C-mode, the start and end lines are
> not created -- am I supposed to add header-mode-line/make-divisor &
> header-end-line to make-header-hooks?
Oops. Place 'header-mode-line as the first hook and 'header-end-line as the
last hook.

> Each time make-revision is executed, a new HISTORY line is created, I
> think case-fold-search should be set to t in that function. 
My make-revisions do not make a new history line, but I run with
case-fold-search t.  In the future, I will bind case-fold-search to t as
you suggest for robustnest. 

> The header-mode-line would have been ideal for setting the mode in
> editing shell scripts, but unfortunately Emacs seems to want it in the
> first line, which is used for the "#! interpreter"..
Change the following in files.el or dump this into site-init.el or your
.emacs file.  Note: generic-code-mode from Cesar Quiroz is very good for
shell scripts.

(defun set-auto-mode () ;; Modified to look on first OR second line
  "Select major mode appropriate for current buffer.
May base decision on visited file name (See variable  auto-mode-list)
or on buffer contents (-*- line or local variables spec), but does not look
for the \"mode:\" local variable.  For that, use  hack-local-variables."
  ;; Look for -*-MODENAME-*- or -*- ... mode: MODENAME; ... -*-
  (let (beg end mode)
    (save-excursion
      (goto-char (point-min))
      (skip-chars-forward " \t\n")
      (if (and (search-forward "-*-" (save-excursion (forward-line 1)(end-of-line) (point)) t)
	       (progn
		 (skip-chars-forward " \t")
		 (setq beg (point))
		 (search-forward "-*-" (save-excursion (forward-line 1)(end-of-line) (point)) t))
	       (progn
		 (forward-char -3)
		 (skip-chars-backward " \t")
		 (setq end (point))
		 (goto-char beg)
		 (if (search-forward ":" end t)
		     (progn
		       (goto-char beg)
		       (if (let ((case-fold-search t))
			     (search-forward "mode:" end t))
			   (progn
			     (skip-chars-forward " \t")
			     (setq beg (point))
			     (if (search-forward ";" end t)
				 (forward-char -1)
			       (goto-char end))
			     (skip-chars-backward " \t")
			     (setq mode (buffer-substring beg (point))))))
		   (setq mode (buffer-substring beg end)))))
	  (funcall (intern (concat (downcase mode) "-mode")))
	(let ((alist auto-mode-alist)
	      (name buffer-file-name))
	  (let ((case-fold-search (eq system-type 'vax-vms)))
	    ;; Remove backup-suffixes from file name.
	    (setq name (file-name-sans-versions name))
	    ;; Find first matching alist entry.
	    (while (and (not mode) alist)
	      (if (string-match (car (car alist)) name)
		  (setq mode (cdr (car alist))))
	      (setq alist (cdr alist))))
	  (if mode (funcall mode)))))))