initial version of bigclean-emacs,from svn to git
[bigclean-emacs.git] / emacs / .emacs.d / site-lisp / header2.el
blob083f4179b53c9c97462d77bcc7001ef11569a5db
1 ;;; header2.el --- Support for creation and update of file headers.
2 ;;
3 ;; Filename: header2.el
4 ;; Description: Support for creation and update of file headers.
5 ;; Author: Lynn Slater
6 ;; Drew Adams
7 ;; Maintainer: Drew Adams
8 ;; Copyright (C) 1996-2009, Drew Adams, all rights reserved.
9 ;; Copyright (C) 1989 Free Software Foundation, Inc.
10 ;; Copyright (C) 1988 Lynn Randolph Slater, Jr.
11 ;; Created: Tue Aug 4 17:06:46 1987
12 ;; Version: 21.0
13 ;; Last-Updated: Sun Oct 25 09:23:39 2009 (-0700)
14 ;; By: dradams
15 ;; Update #: 1710
16 ;; URL: http://www.emacswiki.org/cgi-bin/wiki/header2.el
17 ;; Keywords: tools, docs, maint, abbrev, local
18 ;; Compatibility: GNU Emacs: 20.x, 21.x, 22.x, 23.x
20 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
22 ;;; Commentary:
24 ;; Support for creation and update of file headers.
26 ;; Some of this code and commentary were originally written by Lynn
27 ;; Slater as file `header.el'. Drew Adams updated it and maintains it
28 ;; as `header2.el'. The original is here:
29 ;; `http://www.emacswiki.org/cgi-bin/wiki/download/OriginalHeaderEl'.
31 ;; Commands (interactive functions) defined here:
33 ;; `make-header', `make-revision', `make-divider',
34 ;; `make-box-comment', `update-file-header'.
36 ;; Other functions defined here:
38 ;; `auto-make-header', `auto-update-file-header',
39 ;; `delete-and-forget-line', `header-AFS', `header-author',
40 ;; `header-blank', `header-code', `header-commentary',
41 ;; `header-compatibility', `header-copyright',
42 ;; `header-creation-date', `header-date-string',
43 ;; `header-description', `header-end-line', `header-eof',
44 ;; `header-file-name', `header-free-software', `header-history',
45 ;; `header-keywords', `header-lib-requires', `header-maintainer',
46 ;; `header-mode-line', `header-modification-author',
47 ;; `header-modification-date', `header-prefix-string',
48 ;; `header-rcs-id', `header-rcs-log', `header-sccs', `header-shell',
49 ;; `header-status', `header-title', `header-toc',
50 ;; `header-update-count', `header-version', `headerable-file-p',
51 ;; `make-box-comment', `make-divider', `make-header',
52 ;; `make-revision', `register-file-header-action',
53 ;; `section-comment-start', `true-mode-name', `uniquify-list',
54 ;; `update-file-name', `update-last-modified-date',
55 ;; `update-last-modifier', `update-lib-requires',
56 ;; `update-write-count'.
58 ;; User options (variables) defined here:
60 ;; `header-copyright-notice', `header-date-format',
61 ;; `header-history-label', `header-max', `make-header-hook'.
63 ;; Other variables defined here:
65 ;; `file-header-update-alist', `header-prefix-string', `return-to'.
68 ;; To have Emacs update file headers automatically whenever you save a
69 ;; file, put this in your init file (~/.emacs):
71 ;; (add-hook 'write-file-hooks 'auto-update-file-header)
73 ;; To have Emacs add a file header whenever you create a new file in
74 ;; some mode, put this in your init file (~/.emacs):
76 ;; (add-hook 'emacs-lisp-mode-hook 'auto-make-header)
77 ;; (add-hook 'c-mode-common-hook 'auto-make-header)
78 ;; ...
82 ;; From the original header.el text by Lynn Slater:
84 ;; This file is particularly useful with the file-declarations
85 ;; package also by Lynn Slater. Read the first 20% of this file
86 ;; to learn how to customize.
88 ;; From: eddie.mit.edu!think!ames!indetech.com!lrs (Lynn Slater)
89 ;; To: info-gnu-emacs@prep.ai.mit.edu
90 ;; Subject: Automatic header creation and maintenance
91 ;; Date: Wed, 1 Nov 89 09:33 PST
93 ;; Enclosed is code to automatically create and maintain file
94 ;; headers. This code is cleaner and mush more easily customized
95 ;; than any of my previous header postings.
97 ;; New in this release are customizations that allow headers to be
98 ;; created and maintained from the command line. This is good for
99 ;; projects with some vi die-hards or when headers are being added
100 ;; in mass for the first time.
102 ;; Example:
103 ;; cd $EMACS/lisp
104 ;; headers -make *.el
106 ;; I have found file headers to be very valuable in project
107 ;; development. I always know who has been where and how many
108 ;; times they were there. Most often, I also know what they did.
109 ;; The update count and last modified date are very useful in
110 ;; determining the proper version of a file to use. I have often
111 ;; thought that it would be easier to integrate patches from
112 ;; individuals to gnu tools such as gcc and g++ if I knew for
113 ;; certain what version of a particular file they were working
114 ;; from. If all had headers, I would see the update count and
115 ;; date in the "diff -c" output and would be able to find or
116 ;; recreate the file to patch accordingly.
118 ;; In this message are three files:
119 ;; header.el - Emacs header functions and instructions
120 ;; headers.1 - Man page for command line headers useage
121 ;; headers - Shell script for command-line headers.
123 ;; Text by Lynn Slater, updated as needed:
125 ;; Mode-specific headers:
126 ;; ---------------------
127 ;; Not all headers need look alike. Suppose that you have a unix script mode
128 ;; and want it to have a shell specifier line that all other headers do not
129 ;; have. To do this, Place the following lines in a hook called when the
130 ;; mode is invoked or in the code that establishes the mode:
131 ;; (make-local-hook 'make-header-hook)
132 ;; (add-hook make-header-hook 'header-shell)
134 ;; The header building blocks are sensitive to the different comment
135 ;; characters in different modes.
137 ;; Mode specific update actions:
138 ;; ----------------------------
139 ;; Suppose something needs to be automatically maintained only in certain
140 ;; modes. An example is the .TH macro in man pages. You can create mode-
141 ;; specific update actions by placing lines such as the following in the mode
142 ;; creation function of the mode hook.
143 ;; (make-local-hook 'file-header-update-alist)
144 ;; (register-file-header-action
145 ;; "^\.TH[ \t]+[^\" \t]+[ \t]+[^\" \t]+[ \t]+\"\\([^\"]*\\)\""
146 ;; 'update-last-modified-date-macro)
148 ;; Define individual header elements. These are the building blocks
149 ;; used to construct a site specific header. You may add your own
150 ;; functions either in this file or in your `.emacs' file. The
151 ;; variable `make-header-hook' specifies the functions that will
152 ;; actually be called.
154 ;; Note on change-control systems:
156 ;; If you use `header2.el' in a change-control system, such as RCS,
157 ;; you might need to leave it checked out. This is because any
158 ;; change-control keywords in the file will be expanded during
159 ;; check-in. Normally, you will want those keywords to be inserted
160 ;; in file headers unexpanded.
162 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
164 ;;; Change log:
166 ;; 2009/10/25 dadams
167 ;; Renamings from lib-require.el. If you use that library, you must update it.
168 ;; lib-requires-header -> libreq-file-header
169 ;; insert-lib-requires-as-comment -> libreq-insert-lib-requires-as-comment
170 ;; 2009/09/24 dadams
171 ;; header-multiline: Use a marker for END, and go to it after insert multiline.
172 ;; header-eof: Go to point-max and insert newline.
173 ;; 2008/09/06 dadams
174 ;; update-write-count: Keep rest of line, after number. Thx to Johan Vromans.
175 ;; Added update-VCS-version, commented out.
176 ;; 2008/08/06 dadams
177 ;; header-date-string: Use %z, not %Z - the latter no longer works on Windows.
178 ;; 2008/07/11 dadams
179 ;; header-title, header-file-name, header-eof:
180 ;; Use buffer-file-name, if available. Thx Juan Miguel Cejuela for suggestion.
181 ;; 2008/03/14 dadams
182 ;; header-free-software: Update version 2 -> version 3 of GPL.
183 ;; 2008/01/18 dadams
184 ;; header-creation-date: Added time zone also. Thx to Sebastian Luque.
185 ;; Added: header-date-(string|format).
186 ;; header-creation-date, update-last-modified-date: Use header-date-format.
187 ;; 2007/12/12 dadams
188 ;; INCOMPATIBLE CHANGE - If you previously used update-file-header as a
189 ;; write-file-hook, change it to auto-update-file-header.
190 ;; Added auto-update-file-header. Uses new update-file-header.
191 ;; update-file-header: Made unconditional. Thx to Lennart Borgman.
192 ;; 2007/03/25 dadams
193 ;; make-header: Use let*, so comment-end-p is bound in header-prefix-string.
194 ;; 2006/01/13 dadams
195 ;; Added: header-url.
196 ;; 2006/01/07 dadams
197 ;; Added :link.
198 ;; 2005/11/04 dadams
199 ;; update-last-modified-date: Added timezone.
200 ;; 2005/10/21 dadams
201 ;; Added header-free-software, header-multiline (vars & fns).
202 ;; Updated make-header-hooks.
203 ;; update-lib-requires:
204 ;; Use error msg if insert-lib-requires-as-comment errors.
205 ;; Made buffer-file-name filter outermost.
206 ;; Got rid of locate-library filter.
207 ;; header-code, header-eof: Include comment-end case.
208 ;; Changed defvar to defcustom.
209 ;; auto-make-header: Make sure its a file buffer.
210 ;; Protect lib-requires-header with boundp.
211 ;; Renamed make-header-hooks to make-header-hook.
212 ;; Cleaned up Commentary. Added .emacs instructions, note on change control.
213 ;; header-prefix-string: Don't bother to bind comment-end-p.
214 ;; 2005/10/19 dadams
215 ;; Increased header max default value from 2000 to 50000.
216 ;; 2005/10/18 dadams
217 ;; Added: update-lib-requires, header-lib-requires, header-version.
218 ;; make-header-hooks:
219 ;; Use header-version, not header-rcs-id. Use header-lib-requires.
220 ;; Don't use header-rcs-log.
221 ;; update-last-modifier: inlined code for non-empty-name-p.
222 ;; Require lib-requires.el.
223 ;; 2004/10/01 dadams
224 ;; auto-make-header: not if read-only
225 ;; header-rcs-log: Split string so it won't be overwritten by vc.el
226 ;; Thanks to Steve Taylor for this fix.
227 ;; 2004/06/04 dadams
228 ;; header-eof: Removed "`" and "'" around file name.
229 ;; 1996/04/04 dadams
230 ;; Mods for modes like C, etc.
231 ;; 1. make-header-hooks: Removed header-blank before: header-commentary,
232 ;; header-history and header-code. Added 2 header-blank's after
233 ;; header-commentary.
234 ;; 2. Added section-comment-start.
235 ;; 3. header-file-name: Only use header-prefix-string if 1-char comment-start.
236 ;; 4. header-commentary,header-history,header-code: Use section-comment-start.
237 ;; 5. header-code: Only add ":\n\n\n\n\n" if 1-char comment-start.
238 ;; 6. header-eof: Removed extra " ".
239 ;; 1996/03/18 dadams
240 ;; Added defvars for return-to, explicit-shell-file-name, c-style .
241 ;; 1996/02/12 dadams
242 ;; Added auto-make-header.
243 ;; 1995/09/04 dadams
244 ;; Adapted to std GNU maintenance form (see file lisp-mnt.el).
245 ;; 1) Distinguished sections from subsections. Changed order.
246 ;; 2) No longer use header-mode-line (conflicts with GNU maintenance std).
247 ;; 3) Added header-eof, header-history-label.
248 ;; 4) Removed header-purpose (use just header-commentary).
249 ;; 5) Redefined: make-revision, header-file-name, header-history,
250 ;; header-rcs-id, header-sccs, header-copyright.
251 ;; 1995/08/08 dadams
252 ;; Added header-maintainer, header-keywords, header-commentary, header-code.
253 ;; 1995/08/02 dadams
254 ;; header-rcs -> header-rcs-id, header-rcs-log, and changed order.
255 ;; 1995/07/31 dadams
256 ;; 1. Corrected SCCS & RCS strings (need to be uninstantiated here).\
257 ;; 2. Added defvar for header-prefix-string (not really needed).
258 ;; 3. Commented out stuff that needs Lynn Slater's command-line-hooks.
259 ;; 28-Apr-1995 dadams
260 ;; Added default for comment-start in make-revision.
261 ;; 11/11/89 -- Darryl Okahata, HP NMD (darrylo%hpnmd@hpcea.HP.COM)
262 ;; 25-Sep-1989 Lynn Slater
263 ;; added -default-mode ahd headerable-file-p
264 ;; 10-Sep-1989 Lynn Slater
265 ;; Seperated out header-mode-line and header-end. Headers are now really
266 ;; easy to modify. Added instructions for mode-specific headers.
267 ;; 8-Aug-1989 Lynn Slater
268 ;; Changed structure to allow site/user customized headers
269 ;; 24-Jun-1989 Lynn Slater
270 ;; restructured file, made the order of header actions not be significant.
271 ;; 22-Jun-1989 Lynn Slater
272 ;; Made file header actions easier to declare
273 ;; Made sccs and rcs support be user settable.
274 ;; Added c-style support
275 ;; 25-Jan-1989 Lynn Slater
276 ;; Added make-doc command
277 ;; 25-Jan-1989 Lynn Slater
278 ;; made the make-revision command include the last-modified data
279 ;; 31-Aug-1988 Lynn Slater
280 ;; Made the make-revision work in most modes
281 ;; Added the update-file-name command
282 ;; 1-Mar-1988 Lynn Slater
283 ;; made the headers be as sensitive as possible to the proper
284 ;; comment chars.
285 ;; 1-Mar-1988 Lynn Slater
286 ;; Made the mode be declared in each header
287 ;; 26-Feb-1988 Lynn Slater
288 ;; added the make-revision call
290 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
292 ;; This program is free software; you can redistribute it and/or modify
293 ;; it under the terms of the GNU General Public License as published by
294 ;; the Free Software Foundation; either version 3, or (at your option)
295 ;; any later version.
297 ;; This program is distributed in the hope that it will be useful,
298 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
299 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
300 ;; GNU General Public License for more details.
302 ;; You should have received a copy of the GNU General Public License
303 ;; along with this program; see the file COPYING. If not, write to
304 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
305 ;; Floor, Boston, MA 02110-1301, USA.
307 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
309 ;;; Code:
311 (and (< emacs-major-version 20) (eval-when-compile (require 'cl))) ;; when, unless
312 (require 'lib-requires nil t)
313 ;; (no error if not found):
314 ;; libreq-insert-lib-requires-as-comment, libreq-file-header
316 ;;;;;;;;;;;;;;;;;;;;;;
318 (provide 'header2)
319 (require 'header2) ; Ensure loaded before compile.
322 ;; Expect to get byte-compiler error messages such as the following:
324 ;; While compiling header-multiline:
325 ;; ** reference to free variable comment-end-p
326 ;; ** reference to free variable comment-start-p
327 ;; While compiling header-code:
328 ;; ** reference to free variable comment-end-p
329 ;; While compiling header-eof:
330 ;; ** reference to free variable comment-end-p
331 ;; ** reference to free variable comment-start-p
332 ;; While compiling header-mode-line:
333 ;; ** reference to free variable comment-start-p
334 ;; While compiling header-end-line:
335 ;; ** reference to free variable comment-end-p
336 ;; ** reference to free variable comment-start-p
337 ;; While compiling header-prefix-string:
338 ;; ** reference to free variable comment-end-p
340 ;;;;;;;;;;;;;;;;;;;;;;
344 ;; User Options (Variables) --------------------------------
346 (defgroup Automatic-File-Header nil
347 "File header insertion and updating."
348 :group 'files :group 'editing :group 'convenience :group 'programming
349 :group 'development
350 :link `(url-link :tag "Send Bug Report"
351 ,(concat "mailto:" "drew.adams" "@" "oracle" ".com?subject=\
352 header2.el bug: \
353 &body=Describe bug here, starting with `emacs -q'. \
354 Don't forget to mention your Emacs and library versions."))
355 :link '(url-link :tag "Other Libraries by Drew"
356 "http://www.emacswiki.org/cgi-bin/wiki/DrewsElispLibraries")
357 :link '(url-link :tag "Download"
358 "http://www.emacswiki.org/cgi-bin/wiki/header2.el")
359 :link '(url-link :tag "Description"
360 "http://www.emacswiki.org/cgi-bin/wiki/AutomaticFileHeaders#header2")
361 :link '(emacs-commentary-link :tag "Commentary" "header2")
364 (defcustom header-max 50000
365 "*Maximum number of chars to examine for header updating."
366 :type 'integer :group 'Automatic-File-Header)
368 (defcustom header-copyright-notice nil
369 "*Copyright notice to be inserted into file headers."
370 :type '(choice (const :tag "No copyright notice (value nil)" nil) string)
371 :group 'Automatic-File-Header)
373 (defcustom header-date-format t
374 "Date/time format for header timestamp.
375 The value can be a string, t, or nil.
376 A string value is passed to `format-time-string'.
377 t means use local time with timezone; nil means use UTC."
378 :group 'Automatic-File-Header
379 :type '(choice
380 (const :tag "Local time, with timezone" t)
381 (const :tag "UTC" nil)
382 (string :tag "Custom format")))
384 ;; Change this as you like.
385 ;; Note that the Elisp manual, node Library Headers, suggests putting copyright just
386 ;; after header-description. That is not done here, by default, because I feel that
387 ;; copyright is not the first information people are looking for. Otherwise, this
388 ;; default value corresponds to what the Elisp manual recommends for Emacs Lisp.
389 (defcustom make-header-hook '(
390 ;;header-mode-line
391 header-title
392 header-blank
393 header-file-name
394 header-description
395 ;;header-status
396 header-author
397 header-maintainer
398 header-copyright
399 header-creation-date
400 ;;header-rcs-id
401 header-version
402 ;;header-sccs
403 header-modification-date
404 header-modification-author
405 header-update-count
406 header-url
407 header-keywords
408 header-compatibility
409 header-blank
410 header-lib-requires
411 header-end-line
412 header-commentary
413 header-blank
414 header-blank
415 header-blank
416 header-end-line
417 header-history
418 header-blank
419 header-blank
420 ;; header-rcs-log
421 header-end-line
422 header-free-software
423 header-code
424 header-eof
426 "*Functions that insert header elements.
427 Each function is started on a new line and is expected to end in a new line.
428 Each function may insert any number of lines, but each line, including the
429 first, must be started with the value of `header-prefix-string'.
430 \(This variable holds the same value as would be returned by calling
431 `header-prefix-string' but is faster to access.) Each function may set the
432 following global variables:
434 `header-prefix-string' -- mode-specific comment sequence
435 `return-to' -- character position to which point will be moved after header
436 functions are processed. Any header function may set this,
437 but only the last setting will take effect.
439 It is reasonable to locally set these hooks according to certain modes.
440 For example, a table of contents might only apply to code development modes
441 and `header-shell' might only apply to shell scripts. See instructions in
442 file `header2.el' to do this."
443 :type 'hook :group 'Automatic-File-Header)
445 (defcustom header-history-label "Change log:" ; Was "HISTORY:" before.
446 "*Label introducing change log history."
447 :type 'string :group 'Automatic-File-Header)
449 (defcustom header-free-software
450 "This program is free software; you can redistribute it and/or
451 modify it under the terms of the GNU General Public License as
452 published by the Free Software Foundation; either version 3, or
453 \(at your option) any later version.
455 This program is distributed in the hope that it will be useful,
456 but WITHOUT ANY WARRANTY; without even the implied warranty of
457 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
458 General Public License for more details.
460 You should have received a copy of the GNU General Public License
461 along with this program; see the file COPYING. If not, write to
462 the Free Software Foundation, Inc., 51 Franklin Street, Fifth
463 Floor, Boston, MA 02110-1301, USA."
465 "*Text saying that this is free software"
466 :type 'string :group 'Automatic-File-Header)
471 ;;; Internal variables -------------------------------------
473 (defvar return-to nil
474 "Position to move point to after header fns are processed.
475 Any header function may set this. The last setting will take effect.")
477 (defvar header-multiline ""
478 "Multiline text to be inserted as a comment.
479 Leave the global value of this as\"\", and bind the value as needed.")
481 (defvar file-header-update-alist ()
482 "Used by `update-file-header' to know what to do in a file.
483 Is a list of sets of cons cells where the car is a regexp string and the cdr is
484 the function to call if the string is found near the start of the file.")
486 (defvar header-prefix-string ""
487 "Mode-specific comment prefix string for use in headers.")
489 ;; To quiet the byte compiler.
490 (defvar explicit-shell-file-name) (defvar c-style)
495 ;;; Functions ----------------------------------------------
497 (defsubst header-blank ()
498 "Insert an empty comment to file header (after `header-prefix-string')."
499 (insert header-prefix-string "\n"))
501 ;; Major section headings
503 (defsubst section-comment-start ()
504 "Comment start of major section headings."
505 (if (= (length comment-start) 1) ; e.g. Lisp: ";; \n;;;"
506 (concat header-prefix-string "\n" comment-start header-prefix-string)
507 (concat "\n" comment-start))) ; e.g. C: "\n/*"
509 (defsubst header-title ()
510 "Insert buffer's file name and leave room for a description.
511 In `emacs-lisp-mode', this should produce the title line for library
512 packages."
513 (insert (concat comment-start (and (= 1 (length comment-start))
514 header-prefix-string)
515 (if (buffer-file-name)
516 (file-name-nondirectory (buffer-file-name))
517 (buffer-name))
518 " --- " "\n"))
519 (setq return-to (1- (point))))
521 (defsubst header-file-name ()
522 "Insert \"Filename: \" line, using buffer's file name."
523 (insert header-prefix-string "Filename: "
524 (if (buffer-file-name)
525 (file-name-nondirectory (buffer-file-name))
526 (buffer-name))
527 "\n"))
529 (defsubst header-description ()
530 "Insert \"Description: \" line."
531 (insert header-prefix-string "Description: \n"))
533 (defsubst header-author ()
534 "Insert current user's name (`user-full-name') as this file's author."
535 (insert header-prefix-string "Author: " (user-full-name) "\n"))
537 (defsubst header-maintainer ()
538 "Insert \"Maintainer: \" line."
539 (insert header-prefix-string "Maintainer: \n"))
541 (defun header-copyright ()
542 "Insert `header-copyright-notice', unless nil."
543 (when header-copyright-notice
544 (let ((start (point)))
545 (insert header-copyright-notice)
546 (save-restriction
547 (narrow-to-region start (point))
548 (goto-char (point-min))
549 ;; Must now insert header prefix. Cannot just replace string,
550 ;; because that would cause too many undo boundries.
551 (insert header-prefix-string)
552 (while (progn (skip-chars-forward "^\n") (looking-at "\n"))
553 (forward-char 1) (unless (eolp) (insert header-prefix-string)))
554 (goto-char (point-max))))))
556 (defsubst header-creation-date ()
557 "Insert today's time, date, and time zone as file creation date."
558 (insert header-prefix-string "Created: ")
559 (insert (header-date-string) "\n"))
561 (defun header-date-string ()
562 "Current date and time."
563 (format-time-string
564 (cond ((stringp header-date-format) header-date-format)
565 (header-date-format "%a %b %e %T %Y (%z)")
566 (t "%a %b %e %T %Y (UTC)"))
567 (current-time)
568 (not header-date-format)))
570 (defsubst header-rcs-id ()
571 "Insert lines to record RCS id information (\"$Id$\n\")."
572 (insert header-prefix-string "Version: $Id$\n"))
574 (defsubst header-version ()
575 "Insert lines to record version information."
576 (insert header-prefix-string "Version: \n"))
578 (defsubst header-sccs ()
579 "Insert a line to record SCCS version information."
580 (insert header-prefix-string "Version: %W% %E% %U%\n"))
582 (defsubst header-commentary ()
583 "Insert \"Commentary: \" line."
584 (insert (concat (section-comment-start) "Commentary: \n")))
586 (defsubst header-history ()
587 "Insert `header-history-label' into header for use by `make-revision'.
588 Without this, `make-revision' inserts `header-history-label' after the header."
589 (insert (concat (section-comment-start) header-history-label "\n")))
591 (defun header-free-software ()
592 "Insert text saying that this is free software."
593 (let ((header-multiline header-free-software))
594 (header-multiline)))
596 ;; Variable `comment-end-p' is free here. It is bound in `make-header'.
597 (defun header-multiline ()
598 "Insert multiline comment. The comment text is in `header-multiline'."
599 (let ((lineno 1)
600 beg end nb-lines)
601 (beginning-of-line)
602 (if comment-end-p
603 (insert "\n" comment-start)
604 (header-blank)
605 (insert header-prefix-string))
606 (setq beg (point))
607 (insert header-multiline)
608 (setq end (point-marker))
609 (setq nb-lines (count-lines beg end))
610 (goto-char beg)
611 (forward-line 1)
612 (while (< lineno nb-lines)
613 (insert header-prefix-string)
614 (forward-line 1)
615 (setq lineno (1+ lineno)))
616 (goto-char end)
617 (when comment-end-p (insert "\n"))
618 (insert comment-end)
619 (insert "\n")
620 (unless comment-end-p
621 (header-blank)
622 (header-end-line))))
624 ;; Variable `comment-end-p' is free here. It is bound in `make-header'.
625 (defsubst header-code ()
626 "Insert \"Code: \" line."
627 (insert (concat (section-comment-start) "Code:" (and comment-end-p comment-end)
628 "\n\n\n")))
630 ;; Variable `comment-end-p' is free here. It is bound in `make-header'.
631 (defsubst header-eof ()
632 "Insert comment indicating end of file."
633 (goto-char (point-max))
634 (insert "\n")
635 (unless comment-end-p (header-end-line))
636 (insert comment-start
637 (concat (and (= 1 (length comment-start)) header-prefix-string)
638 (if (buffer-file-name)
639 (file-name-nondirectory (buffer-file-name))
640 (buffer-name))
641 " ends here"
642 (if comment-end-p comment-end "\n"))))
644 (defsubst header-modification-date ()
645 "Insert todays date as the time of last modification.
646 This is normally overwritten with each file save."
647 (insert header-prefix-string "Last-Updated: \n"))
649 (defsubst header-modification-author ()
650 "Insert current user's name as the last person who modified the file.
651 This is normally overwritten with each file save."
652 (insert header-prefix-string " By: \n"))
654 (defsubst header-update-count ()
655 "Insert a count of the number of times the file has been saved."
656 (insert header-prefix-string " Update #: 0\n"))
658 (defsubst header-url ()
659 "Insert \"URL: \" line."
660 (insert header-prefix-string "URL: \n"))
662 (defsubst header-keywords ()
663 "Insert \"Keywords: \" line."
664 (insert header-prefix-string "Keywords: \n"))
666 (defsubst header-compatibility ()
667 "Insert a \"Compatibility: \" line."
668 (insert header-prefix-string "Compatibility: \n"))
670 (defsubst header-lib-requires ()
671 "Insert list of libraries required by this one."
672 (when (and (eq major-mode 'emacs-lisp-mode) (boundp 'libreq-file-header))
673 (insert libreq-file-header) ; Defined in `lib-requires.el'.
674 (insert ";; None\n;;\n")))
676 (defsubst header-status ()
677 "Insert a \"Status: \" line."
678 (insert header-prefix-string "Status: \n"))
680 (defsubst header-toc ()
681 "Insert a \"Table of Contents: \" line."
682 (insert header-prefix-string "Table of Contents: \n" header-prefix-string
683 "\n"))
685 (defsubst header-rcs-log ()
686 "Insert lines to record RCS log information (\"$Log$\n\")."
687 (insert header-prefix-string
688 (concat "RCS $" ; String split prevents `vc.el' overwrite.
689 "Log$\n"))) ; Thanks to Steve Taylor.
691 (defsubst header-AFS ()
692 "Insert a line to record SHAPE information."
693 (insert header-prefix-string "AFSID: $__Header$\n"))
695 (defsubst header-shell ()
696 "Insert a kernal shell specifier line.
697 Uses the same shell named in `explicit-shell-file-name', the ESHELL
698 environment variable, the SHELL environment variable, or
699 '/bin/sh'. (This is the same shell that the shell command uses.)"
700 (insert "#!" (or (and (boundp 'explicit-shell-file-name)
701 explicit-shell-file-name)
702 (getenv "ESHELL")
703 (getenv "SHELL")
704 "/bin/sh")
705 "\n"))
707 ;; Variable `comment-start-p' is free here. It is bound in `make-header'.
708 (defun header-mode-line ()
709 "Insert a \" -*- Mode: \" line."
710 (let* ((mode-declaration
711 (concat " -*- Mode: " (true-mode-name)
712 (if (assoc 'c-style (buffer-local-variables))
713 (concat "; C-Style: " (symbol-name c-style))
715 " -*- "))
716 (md-length (length mode-declaration)))
717 (insert (cond ((and comment-start (= 1 (length comment-start)))
718 ;; Assume comment start char is also fill char.
719 (concat comment-start comment-start
720 (make-string (/ (- 77 md-length) 2)
721 (aref comment-start 0))
722 mode-declaration
723 (make-string (/ (- 78 md-length) 2)
724 (aref comment-start 0))))
725 (comment-start-p ; Assume spaces fill the gaps.
726 (concat comment-start
727 (make-string (/ (- 79 md-length
728 (length comment-start)) 2)
729 ?\ )
730 mode-declaration))
731 (t ; No comment-start. Assume Lisp.
732 (concat ";;" (make-string (/ (- 77 md-length) 2) ?\;)
733 mode-declaration
734 (make-string (/ (- 78 md-length) 2) ?\;))))
735 "\n")))
737 ;; Variables `comment-start-p' and `comment-end-p' are free here.
738 ;; They are bound in `make-header'.
739 (defsubst header-end-line ()
740 "Insert a divider line."
741 (insert (cond (comment-end-p comment-end)
742 ((and comment-start (= 1 (length comment-start)))
743 (make-string 70 (aref comment-start 0)))
744 (comment-start-p comment-start)
745 (t (make-string 70 ?\;)))
746 "\n"))
749 ;; User function to declare header actions on a save file.
750 ;; See examples at the end of this file.
751 ;; Invoke from `site-init.el' or in `.emacs'.
752 ;; -------------------------------------------------------
753 (defun register-file-header-action (regexp function-to-call)
754 "Record FUNCTION-TO-CALL as the action to take if REGEXP is found
755 in the file header when a file is written. The function will be called
756 with the cursor located just after the matched REGEXP. Calling this twice
757 with the same args overwrites the previous FUNCTION-TO-CALL."
758 (let ((ml (assoc regexp file-header-update-alist)))
759 (if ml
760 (setcdr ml function-to-call);; overwrite old defn
761 ;; This entry is new to us. Add to the master alist
762 (setq file-header-update-alist (cons (cons regexp function-to-call)
763 file-header-update-alist)))))
766 ;; Register the automatic actions to take for file headers during a save
767 ;; See the second part of the file for explanations.
768 ;; ---------------------------------------------------------------------
769 ;; (register-file-header-action "^.* *\\(.*\\) *\\-\\-" 'update-file-name)
770 ;; (register-file-header-action "\$VERSION[ \t]*=[ \t]*\"\\([0-9]+\\.\\)+"
771 ;; 'update-write-count)
773 (register-file-header-action "Last-Updated[ \t]*: " 'update-last-modified-date)
774 (register-file-header-action " By[ \t]*: " 'update-last-modifier)
775 (register-file-header-action " Update #[ \t]*: " 'update-write-count)
776 (when (boundp 'libreq-file-header)
777 (register-file-header-action libreq-file-header 'update-lib-requires))
780 ;; Header and file division header creation code
781 ;; ---------------------------------------------
782 (defun true-mode-name ()
783 "Return name of mode in a form such that mode may be re-established
784 by calling the function named by appending \"-name\" to this string.
785 This differs from variable `mode-name' in that this is guaranteed to
786 work even when the value has embedded spaces or other junk."
787 (let ((major-mode-name (symbol-name major-mode)))
788 (capitalize (substring major-mode-name 0
789 (or (string-match "-mode" major-mode-name)
790 (length major-mode-name))))))
792 ;; Variable `comment-end-p' is free here. It is bound in `make-header'.
793 (defun header-prefix-string ()
794 "Return a mode-specific prefix string for use in headers.
795 Is sensitive to language-dependent comment conventions."
796 (cond
797 ;; E.g. Lisp.
798 ((and comment-start (= 1 (length comment-start)))
799 (concat comment-start comment-start " "))
801 ;; E.g. C++ and ADA.
802 ;; Special case, three letter comment-start where the first and
803 ;; second letters are the same.
804 ((and comment-start (= 3 (length comment-start))
805 (equal (aref comment-start 1) (aref comment-start 0)))
806 comment-start)
808 ;; E.g. C.
809 ;; Other three-letter comment-start -> grab the middle character
810 ((and comment-start (= 3 (length comment-start)))
811 (concat " " (list (aref comment-start 1)) " "))
813 ((and comment-start (not comment-end-p))
815 ;; Note: no comment end implies that the full comment-start must be
816 ;; used on each line.
817 comment-start)
818 (t ";; "))) ; Use Lisp as default.
820 ;; Usable as a programming language mode hook.
821 ;;;###autoload
822 (defun auto-make-header ()
823 "Call `make-header' if current buffer is empty and is a file buffer."
824 (and (zerop (buffer-size)) (not buffer-read-only) (buffer-file-name)
825 (make-header)))
827 ;;;###autoload
828 (defun make-header ()
829 "Insert (mode-dependent) header comment at beginning of file.
830 A header is composed of a mode line, a body, and an end line. The body is
831 constructed by calling the functions in `make-header-hook'. The mode line
832 and end lines start and terminate block comments. The body lines continue
833 the comment."
834 (interactive)
835 (beginning-of-buffer) ; Leave mark at old location.
836 ;; Use `let*' because `header-prefix-string' refers to `comment-end-p'.
837 (let* ((return-to nil) ; To be set by `make-header-hook'.
838 (comment-start-p (and comment-start (not (string= "" comment-start))))
839 (comment-end-p (and comment-end (not (string= "" comment-end))))
840 (header-prefix-string (header-prefix-string))) ; Cache result.
841 (mapcar (function funcall) make-header-hook)
842 (when return-to (goto-char return-to))))
844 ;;;###autoload
845 (defun make-revision ()
846 "Prepare for a new history revision. Insert history line if inexistant."
847 (interactive)
848 (setq comment-start (or comment-start ";")) ; Use Lisp comment as default.
849 (let ((header-prefix-string (header-prefix-string))
850 (logical-comment-start
851 (if (= 1 (length comment-start))
852 (concat comment-start comment-start " ")
853 comment-start)))
854 ;; Look for the history line
855 (beginning-of-buffer) ; Leave a mark behind.
856 (if (re-search-forward (concat "^\\(" (and comment-start
857 (regexp-quote comment-start))
858 (regexp-quote (header-prefix-string)) "\\|"
859 (if (and comment-start
860 (not (string= "" comment-start)))
861 (concat "\\|"
862 (regexp-quote comment-start))
864 "\\)" " *\\(" header-history-label
865 "\\|HISTORY\\)") ; Backward compatibility.
866 header-max t)
867 (end-of-line)
868 ;; We did not find a history line, add one
869 (goto-char (point-min))
870 ;; find the first line that is not part of the header
871 (while (and (< (point) header-max)
872 (looking-at
873 (concat "[ \t]*\\("
874 (regexp-quote (header-prefix-string))
875 (if (and comment-start
876 (not (string= "" comment-start)))
877 (concat "\\|" (regexp-quote comment-start))
879 (if (and comment-end (not (string= "" comment-end)))
880 (concat "\\|" (regexp-quote comment-end))
882 "\\)")))
883 (forward-line 1))
884 (insert "\n" logical-comment-start header-history-label)
885 (save-excursion (insert "\n" comment-end)))
886 ;; We are now on the line with the header-history-label label
887 (insert "\n" header-prefix-string
888 (let ((str (current-time-string)))
889 (concat (if (equal ?\ (aref str 8))
890 (substring str 9 10)
891 (substring str 8 10))
892 "-" (substring str 4 7) "-" (substring str 20 24)))
893 " " (user-full-name)
894 ;;" |>Ident<|\n"
895 " \n" header-prefix-string " ")
896 ;; Add details about the history of the file before its modification
897 (when (save-excursion
898 (re-search-backward "Last-Updated[ \t]*: \\(.+\\)$" nil t))
899 (insert "Last-Updated: " (buffer-substring (match-beginning 1)
900 (match-end 1)))
901 (if (save-excursion
902 (re-search-backward " Update #[ \t]*: \\([0-9]+\\)$" nil t))
903 (insert " #" (buffer-substring (match-beginning 1) (match-end 1))))
904 (if (save-excursion
905 (re-search-backward " By[ \t]*: \\(.+\\)$" nil t))
906 (insert " (" (buffer-substring (match-beginning 1) (match-end 1))
907 ")"))
908 (insert "\n" header-prefix-string " "))))
910 ;;;###autoload
911 (defun make-divider (&optional end-col)
912 "Insert a comment divider line: the comment start, filler, and end.
913 END-COL is the last column of the divider line."
914 (interactive)
915 (insert comment-start)
916 (when (= 1 (length comment-start)) (insert comment-start))
917 (insert (make-string (max 2 (- (or end-col (- fill-column 2))
918 (length comment-end) 2 (current-column)))
919 (aref comment-start
920 (if (= 1 (length comment-start)) 0 1))))
921 (insert (concat comment-end "\n")))
923 ;;;###autoload
924 (defun make-box-comment (&optional end-col)
925 "Insert an empty (mode dependent) box comment.
926 END-COL is the last column of the divider line."
927 (interactive)
928 (unless (= 0 (current-column)) (forward-line 1))
929 (insert comment-start)
930 (when (= 1 (length comment-start)) (insert comment-start))
931 (unless (char-equal (preceding-char) ? ) (insert ? ))
932 (insert (make-string (max 2 (- (or end-col fill-column ) (length comment-end)
933 2 (current-column)))
934 (aref comment-start
935 (if (= 1 (length comment-start)) 0 1))))
936 (insert "\n" (header-prefix-string) )
937 (save-excursion
938 (insert "\n" (header-prefix-string)
939 (make-string (max 2 (- (or end-col fill-column)
940 (length comment-end) 2 (current-column)))
941 (aref comment-start
942 (if (= 1 (length comment-start)) 0 1)))
943 comment-end "\n")))
946 ;; Automatic Header update code
947 ;; ----------------------------
948 ;;;###autoload
949 (defun update-file-header ()
950 "Update file header.
951 Search the first `header-max' chars in buffer using regexps in
952 `file-header-update-alist'. When a match is found, apply the
953 corresponding function with point located just after the match.
954 The functions can use `match-beginning' and `match-end' to find
955 the strings that cause them to be invoked."
956 (interactive)
957 (save-excursion
958 (save-restriction ; Only search `header-max' chars.
959 (narrow-to-region 1 (min header-max (1- (buffer-size))))
960 (let ((patterns file-header-update-alist))
961 ;; Do not record this call as a command in command history.
962 (setq last-command nil)
963 (while patterns
964 (goto-char (point-min))
965 (when (re-search-forward (car (car patterns)) nil t)
966 ;; Position cursor at end of match.
967 (goto-char (match-end 0))
968 ;;(message "do %s" (car patterns)) (sit-for 1)
969 (funcall (cdr (car patterns))))
970 (setq patterns (cdr patterns)))))))
972 ;;;###autoload
973 (defun auto-update-file-header ()
974 "Update file header if file is modified.
975 If file is modified, size is greater than 100 and buffer is not
976 read only then call `update-file-header."
977 (and (> (buffer-size) 100)
978 (buffer-modified-p)
979 (not buffer-read-only)
980 (update-file-header)
981 nil)) ; Return nil for use as hook.
985 ;; Define individual file header actions. These are the building
986 ;; blocks of automatic header maintenance.
987 ;; -----------------------------------------------------------------------
988 (defsubst delete-and-forget-line ()
989 "Delete current line. Do not add it to the `kill-ring'."
990 (let* ((start (point))
991 (stop (progn (end-of-line) (point)))
992 (str (buffer-substring start stop)))
993 (delete-region start stop)
994 str))
996 (defun update-write-count ()
997 (let* ((str (delete-and-forget-line))
998 (rem (read-from-string str))
999 (num (car rem)))
1000 (if (numberp num)
1001 (insert (format "%s" (1+ num)) (substring str (cdr rem)))
1002 (insert str)
1003 (error "Invalid number for update count `%s'" str))))
1005 ;;; (defun update-VCS-version ()
1006 ;;; "Update VCS version, of the form $VERSION = \"NUM\".
1007 ;;; NUM is a decimal number with one or more decimal points -
1008 ;;; e.g. 3.1415.9265. Only the part after the last decimal point is
1009 ;;; incremented."
1010 ;;; (interactive)
1011 ;;; (let* ((beg (point))
1012 ;;; (eol (save-excursion (end-of-line) (point)))
1013 ;;; (end (re-search-forward "\\([^\\\"]+\\)\"" eol t))
1014 ;;; (str (buffer-substring beg (1- end)))
1015 ;;; (num (car (condition-case err
1016 ;;; (read-from-string str)
1017 ;;; (error (format "Invalid number for version `%s'" str))))))
1018 ;;; (when (>= num most-positive-fixnum)
1019 ;;; (error "Version number is too large to increment: `%s'" num))
1020 ;;; (when (and end (numberp num))
1021 ;;; (let ((newnum (condition-case err2
1022 ;;; (1+ num)
1023 ;;; (error (format "Invalid number for version `%s'" str)))))
1024 ;;; (replace-match (format "%d" newnum) nil nil nil 1)))))
1026 (defsubst update-last-modifier ()
1027 "Update the line that indicates who last modified the file."
1028 (delete-and-forget-line)
1029 (insert (format "%s"
1030 (let ((ufn (user-full-name)))
1031 (if (and ufn (not (string= "" ufn))) ufn (user-login-name))))))
1033 (defsubst update-last-modified-date ()
1034 "Update the line that indicates the last-modified date."
1035 (delete-and-forget-line)
1036 (insert (header-date-string)))
1038 (defun update-file-name ()
1039 "Update the line that indicates the file name."
1040 (beginning-of-line)
1041 ;; Verify looking at a file name for this mode.
1042 (when (looking-at
1043 (concat (regexp-quote (header-prefix-string)) " *\\(.*\\) *\\-\\-"))
1044 (goto-char (match-beginning 1))
1045 (delete-region (match-beginning 1) (match-end 1))
1046 (insert (file-name-nondirectory (buffer-file-name)) " -")))
1048 (defun update-lib-requires ()
1049 "Update the lines that show what libraries are required by this one.
1050 This uses function `libreq-insert-lib-requires-as-comment' from
1051 library `lib-requires.el'.
1053 Note: If a byte-compiled (`*.el') of the library is available, it is
1054 used when determining library dependencies, in preference to the
1055 source library - this is the standard behavior of `load-library'.
1056 The list of required libraries reflects the dependencies indicated in
1057 the byte-compiled file, not the source file. If the bye-compiled file
1058 is out-of-date with respect to its required libraries, so will be the
1059 result of `update-lib-requires'."
1060 (when (buffer-file-name) ; Do nothing if not a file buffer.
1061 (let ((lib (file-name-sans-extension
1062 (file-name-nondirectory (buffer-file-name)))))
1063 (when (and (eq major-mode 'emacs-lisp-mode)
1064 (fboundp 'libreq-insert-lib-requires-as-comment))
1065 (goto-char (match-beginning 0))
1066 ;; Verify looking at `libreq-file-header'"
1067 (when (looking-at (regexp-quote libreq-file-header))
1068 (delete-and-forget-line) (delete-char 1)
1069 (delete-and-forget-line) (delete-char 1)
1070 (while (not (looking-at "^;;$")) (delete-and-forget-line) (delete-char 1))
1071 (delete-and-forget-line) (delete-char 1)
1072 (condition-case err
1073 ;; (let ((load-path (cons (file-name-directory (buffer-file-name))
1074 ;; load-path)))
1075 (libreq-insert-lib-requires-as-comment lib) ; Tries to load LIB.
1076 ;; )
1077 ;; Typically, user just now added `provide' and must load again.
1078 (error (insert libreq-file-header (header-prefix-string) " "
1079 (error-message-string err) ".\n;;\n"))))))))
1083 ;;(setq file-header-update-alist nil)
1084 ;;(setq file-header-update-alist (cdr file-header-update-alist))
1086 ;; Stand-alone Headers
1087 ;; These functions give the ability to invoke headers from the command line.
1088 ;; E.g Can use with `vi' instead of emacs.
1089 ;; -------------------------------------------------------------------------
1090 (defun headerable-file-p (file)
1091 "Return non-nil if FILE is an existing file."
1092 (not (if (not (file-exists-p file))
1093 (message "File \"%s\" does not exist." file)
1094 (if (file-symlink-p file)
1095 (message "\"%s\" is a symbolic link." file)
1096 (if (file-directory-p file)
1097 (message "\"%s\" is a directory." file))))))
1099 (defsubst uniquify-list (list)
1100 "Remove duplicates in list LIST. Comparison is with `eq'."
1101 (let ((rest list))
1102 (while rest
1103 (setcdr rest (delq (car rest) (cdr rest)))
1104 (setq rest (cdr rest)))
1105 list))
1107 ;;(headerable-file-p "AFS")
1108 ;;(headerable-file-p "dbiogen.el")
1109 ;;(headerable-file-p "dbiogen.elc")
1111 ;;; Rest commented out -- Needs Lynn Slater's
1112 ;;; customizations to startup.el to allow command-line-hooks.
1115 ;; (defvar header-required-mode nil
1116 ;; "The mode we force files to be in, regardless of file suffix.")
1118 ;; Define a touch-headers command. This depends upon Lynn Slater's
1119 ;; customizations to startup.el to allow command-line-hooks.
1120 ;; ---------------------------------------------------------------
1121 ;;;(setq command-line-hooks (cons 'touch-headers command-line-hooks))
1122 ;(defun touch-headers ()
1123 ; (if (or (string= argi "-touch") (string= argi "-touch-headers"))
1124 ; (let ((trim-versions-without-asking t)
1125 ; ;; Next line should have a Control-G char, not a space, before `true'.
1126 ; (executing-macro " true"));; suppress "Mark Set" messages
1127 ; ;; Consume all following arguments until one starts with a "-"
1128 ; (while (and command-line-args-left
1129 ; (not (char-equal ?- (aref (car command-line-args-left) 0))))
1130 ; (if (headerable-file-p (car command-line-args-left))
1131 ; (progn
1132 ; (set-buffer (find-file-noselect (car command-line-args-left)))
1133 ; (make-revision)
1134 ; (write-file nil)
1135 ; (kill-buffer (current-buffer))))
1136 ; (setq command-line-args-left (cdr command-line-args-left))))))
1139 ;; Define a make-headers command line option.
1140 ;; ------------------------------------------
1141 ;;;(setq command-line-hooks (cons 'make-headers command-line-hooks))
1142 ;(defun make-headers ()
1143 ; (if (or (string= argi "-make-headers") (string= argi "-make"))
1144 ; (let ((trim-versions-without-asking t)
1145 ; ;; Next line should have a Control-G char, not a space, before `true'.
1146 ; (executing-macro " true"));; suppress "Mark Set" messages
1147 ; ;; Consume all following arguments until one starts with a "-"
1148 ; (while (and command-line-args-left
1149 ; (not (char-equal ?- (aref (car command-line-args-left) 0))))
1151 ; (if (headerable-file-p (car command-line-args-left))
1152 ; (progn
1153 ; (set-buffer (find-file-noselect (car command-line-args-left)))
1154 ; (if header-required-mode
1155 ; (funcall header-required-mode))
1156 ; (make-header)
1157 ; (write-file nil)
1158 ; (message " Mode was %s" major-mode)
1159 ; (kill-buffer (current-buffer))))
1160 ; (setq command-line-args-left (cdr command-line-args-left))))))
1162 ;; Define a -default-mode command line option.
1163 ;; -------------------------------------------
1164 ;;;(setq command-line-hooks (cons 'set-header-mode command-line-hooks))
1165 ;(defun set-header-mode ()
1166 ; (if (or (string= argi "-default-mode")
1167 ; (string= argi "-default"))
1168 ; (let ((trim-versions-without-asking t)
1169 ; ;; Next line should have a Control-G char, not a space, before `true'.
1170 ; (executing-macro " true");; suppress "Mark Set" messages
1171 ; (mode (intern (car command-line-args-left))))
1172 ; (if (memq mode (mapcar 'cdr auto-mode-alist))
1173 ; (progn
1174 ; (setq default-major-mode mode)
1175 ; (message "Default mode is %s" default-major-mode)
1176 ; (setq command-line-args-left (cdr command-line-args-left)))
1177 ; (message "Mode \"%s\" is invalid. Try one of %s" mode
1178 ; (uniquify-list (mapcar 'cdr auto-mode-alist)))
1179 ; (kill-emacs 1)))))
1182 ;; Define a -required-mode command line option.
1183 ;; --------------------------------------------
1184 ;;;(setq command-line-hooks (cons 'set-header-required-mode command-line-hooks))
1185 ;(defun set-header-required-mode ()
1186 ; (if (or (string= argi "-required-mode")
1187 ; (string= argi "-mode"))
1188 ; (let ((trim-versions-without-asking t)
1189 ; ;; Next line should have a Control-G, not a space, char before `true'.
1190 ; (executing-macro " true");; suppress "Mark Set" messages
1191 ; (mode (intern (car command-line-args-left))))
1192 ; (if (memq mode (mapcar 'cdr auto-mode-alist))
1193 ; (progn
1194 ; (setq header-required-mode mode)
1195 ; (message "Required mode is %s" header-required-mode)
1196 ; (setq command-line-args-left (cdr command-line-args-left)))
1197 ; (message "Mode \"%s\" is invalid. Try one of %s" mode
1198 ; (uniquify-list (mapcar 'cdr auto-mode-alist)))
1199 ; (kill-emacs 1)))))
1202 ;; Things in the works or still to do.
1203 ;;------------------------------------
1204 ;; effort.el -- allows an "effort" to be resgistered in the mode line much
1205 ;; like the mode is. The effort then determines some header characteristics
1206 ;; such as copyright. Typical efforts would be 'gdb 'gcc, 'g++, 'emacs, etc.
1207 ;; This would let the copyright (and c-style) be adjusted even within
1208 ;; common modes.
1210 ;; need ez access to values in the header
1211 ;; need a headerp fcn
1213 ;; auto make-revision if current user is not same as last modifier
1214 ;; this would give a history of who touched what.
1217 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1218 ;;; header2.el ends here