OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib-1.10.0/] [etc/] [add-log.el] - Diff between revs 1005 and 1765

Only display areas with differences | Details | Blame | View Log

Rev 1005 Rev 1765
;;; ============ NOTE WELL! =============
;;; ============ NOTE WELL! =============
;;;
;;;
;;; You only need to use this file if you're using a version of Emacs
;;; You only need to use this file if you're using a version of Emacs
;;; prior to 20.1 to work on GDB.  The only difference between this
;;; prior to 20.1 to work on GDB.  The only difference between this
;;; and the standard add-log.el provided with 19.34 is that it
;;; and the standard add-log.el provided with 19.34 is that it
;;; generates dates using the terser format used by Emacs 20.  This is
;;; generates dates using the terser format used by Emacs 20.  This is
;;; the format recommended for use in GDB ChangeLogs.
;;; the format recommended for use in GDB ChangeLogs.
;;;
;;;
;;; To use this code, you should create a directory `~/elisp', save the code
;;; To use this code, you should create a directory `~/elisp', save the code
;;; below in `~/elisp/add-log.el', and then put something like this in
;;; below in `~/elisp/add-log.el', and then put something like this in
;;; your `~/.emacs' file, to tell Emacs where to find it:
;;; your `~/.emacs' file, to tell Emacs where to find it:
;;;
;;;
;;; (setq load-path
;;; (setq load-path
;;;       (cons (expand-file-name "~/elisp")
;;;       (cons (expand-file-name "~/elisp")
;;;             load-path))
;;;             load-path))
;;;
;;;
;;; If you want, you can also byte-compile it --- it'll run a little
;;; If you want, you can also byte-compile it --- it'll run a little
;;; faster, and use a little less memory.  (Not that those matter much for
;;; faster, and use a little less memory.  (Not that those matter much for
;;; this file.)  To do that, after you've saved the text as
;;; this file.)  To do that, after you've saved the text as
;;; ~/elisp/add-log.el, bring it up in Emacs, and type
;;; ~/elisp/add-log.el, bring it up in Emacs, and type
;;;
;;;
;;;     C-u M-x byte-compile-file
;;;     C-u M-x byte-compile-file
;;;
;;;
;;; --- Jim Blandy
;;; --- Jim Blandy
 
 
;;; add-log.el --- change log maintenance commands for Emacs
;;; add-log.el --- change log maintenance commands for Emacs
 
 
;; Copyright (C) 1985, 1986, 1988, 1993, 1994 Free Software Foundation, Inc.
;; Copyright (C) 1985, 1986, 1988, 1993, 1994 Free Software Foundation, Inc.
 
 
;; Keywords: maint
;; Keywords: maint
 
 
;; This file is part of GNU Emacs.
;; This file is part of GNU Emacs.
 
 
;; GNU Emacs is free software; you can redistribute it and/or modify
;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; any later version.
 
 
;; GNU Emacs is distributed in the hope that it will be useful,
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.
;; GNU General Public License for more details.
 
 
;; You should have received a copy of the GNU General Public License
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING.  If not, write to the
;; along with GNU Emacs; see the file COPYING.  If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;; Boston, MA 02111-1307, USA.
 
 
;;; Commentary:
;;; Commentary:
 
 
;; This facility is documented in the Emacs Manual.
;; This facility is documented in the Emacs Manual.
 
 
;;; Code:
;;; Code:
 
 
(defvar change-log-default-name nil
(defvar change-log-default-name nil
  "*Name of a change log file for \\[add-change-log-entry].")
  "*Name of a change log file for \\[add-change-log-entry].")
 
 
(defvar add-log-current-defun-function nil
(defvar add-log-current-defun-function nil
  "\
  "\
*If non-nil, function to guess name of current function from surrounding text.
*If non-nil, function to guess name of current function from surrounding text.
\\[add-change-log-entry] calls this function (if nil, `add-log-current-defun'
\\[add-change-log-entry] calls this function (if nil, `add-log-current-defun'
instead) with no arguments.  It returns a string or nil if it cannot guess.")
instead) with no arguments.  It returns a string or nil if it cannot guess.")
 
 
;;;###autoload
;;;###autoload
(defvar add-log-full-name nil
(defvar add-log-full-name nil
  "*Full name of user, for inclusion in ChangeLog daily headers.
  "*Full name of user, for inclusion in ChangeLog daily headers.
This defaults to the value returned by the `user-full-name' function.")
This defaults to the value returned by the `user-full-name' function.")
 
 
;;;###autoload
;;;###autoload
(defvar add-log-mailing-address nil
(defvar add-log-mailing-address nil
  "*Electronic mail address of user, for inclusion in ChangeLog daily headers.
  "*Electronic mail address of user, for inclusion in ChangeLog daily headers.
This defaults to the value of `user-mail-address'.")
This defaults to the value of `user-mail-address'.")
 
 
(defvar change-log-font-lock-keywords
(defvar change-log-font-lock-keywords
  '(("^[SMTWF].+" . font-lock-function-name-face)       ; Date line.
  '(("^[SMTWF].+" . font-lock-function-name-face)       ; Date line.
    ("^\t\\* \\([^ :\n]+\\)" 1 font-lock-comment-face)  ; File name.
    ("^\t\\* \\([^ :\n]+\\)" 1 font-lock-comment-face)  ; File name.
    ("(\\([^)\n]+\\)):" 1 font-lock-keyword-face))      ; Function name.
    ("(\\([^)\n]+\\)):" 1 font-lock-keyword-face))      ; Function name.
  "Additional expressions to highlight in Change Log mode.")
  "Additional expressions to highlight in Change Log mode.")
 
 
(defvar change-log-mode-map nil
(defvar change-log-mode-map nil
  "Keymap for Change Log major mode.")
  "Keymap for Change Log major mode.")
(if change-log-mode-map
(if change-log-mode-map
    nil
    nil
  (setq change-log-mode-map (make-sparse-keymap))
  (setq change-log-mode-map (make-sparse-keymap))
  (define-key change-log-mode-map "\M-q" 'change-log-fill-paragraph))
  (define-key change-log-mode-map "\M-q" 'change-log-fill-paragraph))
 
 
(defun change-log-name ()
(defun change-log-name ()
  (or change-log-default-name
  (or change-log-default-name
      (if (eq system-type 'vax-vms)
      (if (eq system-type 'vax-vms)
          "$CHANGE_LOG$.TXT"
          "$CHANGE_LOG$.TXT"
        (if (or (eq system-type 'ms-dos) (eq system-type 'windows-nt))
        (if (or (eq system-type 'ms-dos) (eq system-type 'windows-nt))
            "changelo"
            "changelo"
          "ChangeLog"))))
          "ChangeLog"))))
 
 
;;;###autoload
;;;###autoload
(defun prompt-for-change-log-name ()
(defun prompt-for-change-log-name ()
  "Prompt for a change log name."
  "Prompt for a change log name."
  (let* ((default (change-log-name))
  (let* ((default (change-log-name))
         (name (expand-file-name
         (name (expand-file-name
                (read-file-name (format "Log file (default %s): " default)
                (read-file-name (format "Log file (default %s): " default)
                                nil default))))
                                nil default))))
    ;; Handle something that is syntactically a directory name.
    ;; Handle something that is syntactically a directory name.
    ;; Look for ChangeLog or whatever in that directory.
    ;; Look for ChangeLog or whatever in that directory.
    (if (string= (file-name-nondirectory name) "")
    (if (string= (file-name-nondirectory name) "")
        (expand-file-name (file-name-nondirectory default)
        (expand-file-name (file-name-nondirectory default)
                          name)
                          name)
      ;; Handle specifying a file that is a directory.
      ;; Handle specifying a file that is a directory.
      (if (file-directory-p name)
      (if (file-directory-p name)
          (expand-file-name (file-name-nondirectory default)
          (expand-file-name (file-name-nondirectory default)
                            (file-name-as-directory name))
                            (file-name-as-directory name))
        name))))
        name))))
 
 
;;;###autoload
;;;###autoload
(defun find-change-log (&optional file-name)
(defun find-change-log (&optional file-name)
  "Find a change log file for \\[add-change-log-entry] and return the name.
  "Find a change log file for \\[add-change-log-entry] and return the name.
 
 
Optional arg FILE-NAME specifies the file to use.
Optional arg FILE-NAME specifies the file to use.
If FILE-NAME is nil, use the value of `change-log-default-name'.
If FILE-NAME is nil, use the value of `change-log-default-name'.
If 'change-log-default-name' is nil, behave as though it were 'ChangeLog'
If 'change-log-default-name' is nil, behave as though it were 'ChangeLog'
\(or whatever we use on this operating system).
\(or whatever we use on this operating system).
 
 
If 'change-log-default-name' contains a leading directory component, then
If 'change-log-default-name' contains a leading directory component, then
simply find it in the current directory.  Otherwise, search in the current
simply find it in the current directory.  Otherwise, search in the current
directory and its successive parents for a file so named.
directory and its successive parents for a file so named.
 
 
Once a file is found, `change-log-default-name' is set locally in the
Once a file is found, `change-log-default-name' is set locally in the
current buffer to the complete file name."
current buffer to the complete file name."
  ;; If user specified a file name or if this buffer knows which one to use,
  ;; If user specified a file name or if this buffer knows which one to use,
  ;; just use that.
  ;; just use that.
  (or file-name
  (or file-name
      (setq file-name (and change-log-default-name
      (setq file-name (and change-log-default-name
                           (file-name-directory change-log-default-name)
                           (file-name-directory change-log-default-name)
                           change-log-default-name))
                           change-log-default-name))
      (progn
      (progn
        ;; Chase links in the source file
        ;; Chase links in the source file
        ;; and use the change log in the dir where it points.
        ;; and use the change log in the dir where it points.
        (setq file-name (or (and buffer-file-name
        (setq file-name (or (and buffer-file-name
                                 (file-name-directory
                                 (file-name-directory
                                  (file-chase-links buffer-file-name)))
                                  (file-chase-links buffer-file-name)))
                            default-directory))
                            default-directory))
        (if (file-directory-p file-name)
        (if (file-directory-p file-name)
            (setq file-name (expand-file-name (change-log-name) file-name)))
            (setq file-name (expand-file-name (change-log-name) file-name)))
        ;; Chase links before visiting the file.
        ;; Chase links before visiting the file.
        ;; This makes it easier to use a single change log file
        ;; This makes it easier to use a single change log file
        ;; for several related directories.
        ;; for several related directories.
        (setq file-name (file-chase-links file-name))
        (setq file-name (file-chase-links file-name))
        (setq file-name (expand-file-name file-name))
        (setq file-name (expand-file-name file-name))
        ;; Move up in the dir hierarchy till we find a change log file.
        ;; Move up in the dir hierarchy till we find a change log file.
        (let ((file1 file-name)
        (let ((file1 file-name)
              parent-dir)
              parent-dir)
          (while (and (not (or (get-file-buffer file1) (file-exists-p file1)))
          (while (and (not (or (get-file-buffer file1) (file-exists-p file1)))
                      (progn (setq parent-dir
                      (progn (setq parent-dir
                                   (file-name-directory
                                   (file-name-directory
                                    (directory-file-name
                                    (directory-file-name
                                     (file-name-directory file1))))
                                     (file-name-directory file1))))
                             ;; Give up if we are already at the root dir.
                             ;; Give up if we are already at the root dir.
                             (not (string= (file-name-directory file1)
                             (not (string= (file-name-directory file1)
                                           parent-dir))))
                                           parent-dir))))
            ;; Move up to the parent dir and try again.
            ;; Move up to the parent dir and try again.
            (setq file1 (expand-file-name
            (setq file1 (expand-file-name
                         (file-name-nondirectory (change-log-name))
                         (file-name-nondirectory (change-log-name))
                         parent-dir)))
                         parent-dir)))
          ;; If we found a change log in a parent, use that.
          ;; If we found a change log in a parent, use that.
          (if (or (get-file-buffer file1) (file-exists-p file1))
          (if (or (get-file-buffer file1) (file-exists-p file1))
              (setq file-name file1)))))
              (setq file-name file1)))))
  ;; Make a local variable in this buffer so we needn't search again.
  ;; Make a local variable in this buffer so we needn't search again.
  (set (make-local-variable 'change-log-default-name) file-name)
  (set (make-local-variable 'change-log-default-name) file-name)
  file-name)
  file-name)
 
 
;;;###autoload
;;;###autoload
(defun add-change-log-entry (&optional whoami file-name other-window new-entry)
(defun add-change-log-entry (&optional whoami file-name other-window new-entry)
  "Find change log file and add an entry for today.
  "Find change log file and add an entry for today.
Optional arg (interactive prefix) non-nil means prompt for user name and site.
Optional arg (interactive prefix) non-nil means prompt for user name and site.
Second arg is file name of change log.  If nil, uses `change-log-default-name'.
Second arg is file name of change log.  If nil, uses `change-log-default-name'.
Third arg OTHER-WINDOW non-nil means visit in other window.
Third arg OTHER-WINDOW non-nil means visit in other window.
Fourth arg NEW-ENTRY non-nil means always create a new entry at the front;
Fourth arg NEW-ENTRY non-nil means always create a new entry at the front;
never append to an existing entry."
never append to an existing entry."
  (interactive (list current-prefix-arg
  (interactive (list current-prefix-arg
                     (prompt-for-change-log-name)))
                     (prompt-for-change-log-name)))
  (or add-log-full-name
  (or add-log-full-name
      (setq add-log-full-name (user-full-name)))
      (setq add-log-full-name (user-full-name)))
  (or add-log-mailing-address
  (or add-log-mailing-address
      (setq add-log-mailing-address user-mail-address))
      (setq add-log-mailing-address user-mail-address))
  (if whoami
  (if whoami
      (progn
      (progn
        (setq add-log-full-name (read-input "Full name: " add-log-full-name))
        (setq add-log-full-name (read-input "Full name: " add-log-full-name))
         ;; Note that some sites have room and phone number fields in
         ;; Note that some sites have room and phone number fields in
         ;; full name which look silly when inserted.  Rather than do
         ;; full name which look silly when inserted.  Rather than do
         ;; anything about that here, let user give prefix argument so that
         ;; anything about that here, let user give prefix argument so that
         ;; s/he can edit the full name field in prompter if s/he wants.
         ;; s/he can edit the full name field in prompter if s/he wants.
        (setq add-log-mailing-address
        (setq add-log-mailing-address
              (read-input "Mailing address: " add-log-mailing-address))))
              (read-input "Mailing address: " add-log-mailing-address))))
  (let ((defun (funcall (or add-log-current-defun-function
  (let ((defun (funcall (or add-log-current-defun-function
                            'add-log-current-defun)))
                            'add-log-current-defun)))
        paragraph-end entry)
        paragraph-end entry)
 
 
    (setq file-name (expand-file-name (find-change-log file-name)))
    (setq file-name (expand-file-name (find-change-log file-name)))
 
 
    ;; Set ENTRY to the file name to use in the new entry.
    ;; Set ENTRY to the file name to use in the new entry.
    (and buffer-file-name
    (and buffer-file-name
         ;; Never want to add a change log entry for the ChangeLog file itself.
         ;; Never want to add a change log entry for the ChangeLog file itself.
         (not (string= buffer-file-name file-name))
         (not (string= buffer-file-name file-name))
         (setq entry (if (string-match
         (setq entry (if (string-match
                          (concat "^" (regexp-quote (file-name-directory
                          (concat "^" (regexp-quote (file-name-directory
                                                     file-name)))
                                                     file-name)))
                          buffer-file-name)
                          buffer-file-name)
                         (substring buffer-file-name (match-end 0))
                         (substring buffer-file-name (match-end 0))
                       (file-name-nondirectory buffer-file-name))))
                       (file-name-nondirectory buffer-file-name))))
 
 
    (if (and other-window (not (equal file-name buffer-file-name)))
    (if (and other-window (not (equal file-name buffer-file-name)))
        (find-file-other-window file-name)
        (find-file-other-window file-name)
      (find-file file-name))
      (find-file file-name))
    (or (eq major-mode 'change-log-mode)
    (or (eq major-mode 'change-log-mode)
        (change-log-mode))
        (change-log-mode))
    (undo-boundary)
    (undo-boundary)
    (goto-char (point-min))
    (goto-char (point-min))
    (let ((heading (format "%s  %s  <%s>"
    (let ((heading (format "%s  %s  <%s>"
                           (format-time-string "%Y-%m-%d")
                           (format-time-string "%Y-%m-%d")
                           add-log-full-name
                           add-log-full-name
                           add-log-mailing-address)))
                           add-log-mailing-address)))
      (if (looking-at (regexp-quote heading))
      (if (looking-at (regexp-quote heading))
          (forward-line 1)
          (forward-line 1)
        (insert heading "\n\n")))
        (insert heading "\n\n")))
 
 
    ;; Search only within the first paragraph.
    ;; Search only within the first paragraph.
    (if (looking-at "\n*[^\n* \t]")
    (if (looking-at "\n*[^\n* \t]")
        (skip-chars-forward "\n")
        (skip-chars-forward "\n")
      (forward-paragraph 1))
      (forward-paragraph 1))
    (setq paragraph-end (point))
    (setq paragraph-end (point))
    (goto-char (point-min))
    (goto-char (point-min))
 
 
    ;; Now insert the new line for this entry.
    ;; Now insert the new line for this entry.
    (cond ((re-search-forward "^\\s *\\*\\s *$" paragraph-end t)
    (cond ((re-search-forward "^\\s *\\*\\s *$" paragraph-end t)
           ;; Put this file name into the existing empty entry.
           ;; Put this file name into the existing empty entry.
           (if entry
           (if entry
               (insert entry)))
               (insert entry)))
          ((and (not new-entry)
          ((and (not new-entry)
                (let (case-fold-search)
                (let (case-fold-search)
                  (re-search-forward
                  (re-search-forward
                   (concat (regexp-quote (concat "* " entry))
                   (concat (regexp-quote (concat "* " entry))
                           ;; Don't accept `foo.bar' when
                           ;; Don't accept `foo.bar' when
                           ;; looking for `foo':
                           ;; looking for `foo':
                           "\\(\\s \\|[(),:]\\)")
                           "\\(\\s \\|[(),:]\\)")
                   paragraph-end t)))
                   paragraph-end t)))
           ;; Add to the existing entry for the same file.
           ;; Add to the existing entry for the same file.
           (re-search-forward "^\\s *$\\|^\\s \\*")
           (re-search-forward "^\\s *$\\|^\\s \\*")
           (goto-char (match-beginning 0))
           (goto-char (match-beginning 0))
           ;; Delete excess empty lines; make just 2.
           ;; Delete excess empty lines; make just 2.
           (while (and (not (eobp)) (looking-at "^\\s *$"))
           (while (and (not (eobp)) (looking-at "^\\s *$"))
             (delete-region (point) (save-excursion (forward-line 1) (point))))
             (delete-region (point) (save-excursion (forward-line 1) (point))))
           (insert "\n\n")
           (insert "\n\n")
           (forward-line -2)
           (forward-line -2)
           (indent-relative-maybe))
           (indent-relative-maybe))
          (t
          (t
           ;; Make a new entry.
           ;; Make a new entry.
           (forward-line 1)
           (forward-line 1)
           (while (looking-at "\\sW")
           (while (looking-at "\\sW")
             (forward-line 1))
             (forward-line 1))
           (while (and (not (eobp)) (looking-at "^\\s *$"))
           (while (and (not (eobp)) (looking-at "^\\s *$"))
             (delete-region (point) (save-excursion (forward-line 1) (point))))
             (delete-region (point) (save-excursion (forward-line 1) (point))))
           (insert "\n\n\n")
           (insert "\n\n\n")
           (forward-line -2)
           (forward-line -2)
           (indent-to left-margin)
           (indent-to left-margin)
           (insert "* " (or entry ""))))
           (insert "* " (or entry ""))))
    ;; Now insert the function name, if we have one.
    ;; Now insert the function name, if we have one.
    ;; Point is at the entry for this file,
    ;; Point is at the entry for this file,
    ;; either at the end of the line or at the first blank line.
    ;; either at the end of the line or at the first blank line.
    (if defun
    (if defun
        (progn
        (progn
          ;; Make it easy to get rid of the function name.
          ;; Make it easy to get rid of the function name.
          (undo-boundary)
          (undo-boundary)
          (insert (if (save-excursion
          (insert (if (save-excursion
                        (beginning-of-line 1)
                        (beginning-of-line 1)
                        (looking-at "\\s *$"))
                        (looking-at "\\s *$"))
                      ""
                      ""
                    " ")
                    " ")
                  "(" defun "): "))
                  "(" defun "): "))
      ;; No function name, so put in a colon unless we have just a star.
      ;; No function name, so put in a colon unless we have just a star.
      (if (not (save-excursion
      (if (not (save-excursion
                 (beginning-of-line 1)
                 (beginning-of-line 1)
                 (looking-at "\\s *\\(\\*\\s *\\)?$")))
                 (looking-at "\\s *\\(\\*\\s *\\)?$")))
          (insert ": ")))))
          (insert ": ")))))
 
 
;;;###autoload
;;;###autoload
(defun add-change-log-entry-other-window (&optional whoami file-name)
(defun add-change-log-entry-other-window (&optional whoami file-name)
  "Find change log file in other window and add an entry for today.
  "Find change log file in other window and add an entry for today.
Optional arg (interactive prefix) non-nil means prompt for user name and site.
Optional arg (interactive prefix) non-nil means prompt for user name and site.
Second arg is file name of change log.  \
Second arg is file name of change log.  \
If nil, uses `change-log-default-name'."
If nil, uses `change-log-default-name'."
  (interactive (if current-prefix-arg
  (interactive (if current-prefix-arg
                   (list current-prefix-arg
                   (list current-prefix-arg
                         (prompt-for-change-log-name))))
                         (prompt-for-change-log-name))))
  (add-change-log-entry whoami file-name t))
  (add-change-log-entry whoami file-name t))
;;;###autoload (define-key ctl-x-4-map "a" 'add-change-log-entry-other-window)
;;;###autoload (define-key ctl-x-4-map "a" 'add-change-log-entry-other-window)
 
 
;;;###autoload
;;;###autoload
(defun change-log-mode ()
(defun change-log-mode ()
  "Major mode for editing change logs; like Indented Text Mode.
  "Major mode for editing change logs; like Indented Text Mode.
Prevents numeric backups and sets `left-margin' to 8 and `fill-column' to 74.
Prevents numeric backups and sets `left-margin' to 8 and `fill-column' to 74.
New log entries are usually made with \\[add-change-log-entry] or \\[add-change-log-entry-other-window].
New log entries are usually made with \\[add-change-log-entry] or \\[add-change-log-entry-other-window].
Each entry behaves as a paragraph, and the entries for one day as a page.
Each entry behaves as a paragraph, and the entries for one day as a page.
Runs `change-log-mode-hook'."
Runs `change-log-mode-hook'."
  (interactive)
  (interactive)
  (kill-all-local-variables)
  (kill-all-local-variables)
  (indented-text-mode)
  (indented-text-mode)
  (setq major-mode 'change-log-mode
  (setq major-mode 'change-log-mode
        mode-name "Change Log"
        mode-name "Change Log"
        left-margin 8
        left-margin 8
        fill-column 74
        fill-column 74
    indent-tabs-mode t
    indent-tabs-mode t
    tab-width 8)
    tab-width 8)
  (use-local-map change-log-mode-map)
  (use-local-map change-log-mode-map)
  ;; Let each entry behave as one paragraph:
  ;; Let each entry behave as one paragraph:
  ;; We really do want "^" in paragraph-start below: it is only the lines that
  ;; We really do want "^" in paragraph-start below: it is only the lines that
  ;; begin at column 0 (despite the left-margin of 8) that we are looking for.
  ;; begin at column 0 (despite the left-margin of 8) that we are looking for.
  (set (make-local-variable 'paragraph-start) "\\s *$\\|\f\\|^\\sw")
  (set (make-local-variable 'paragraph-start) "\\s *$\\|\f\\|^\\sw")
  (set (make-local-variable 'paragraph-separate) "\\s *$\\|\f\\|^\\sw")
  (set (make-local-variable 'paragraph-separate) "\\s *$\\|\f\\|^\\sw")
  ;; Let all entries for one day behave as one page.
  ;; Let all entries for one day behave as one page.
  ;; Match null string on the date-line so that the date-line
  ;; Match null string on the date-line so that the date-line
  ;; is grouped with what follows.
  ;; is grouped with what follows.
  (set (make-local-variable 'page-delimiter) "^\\<\\|^\f")
  (set (make-local-variable 'page-delimiter) "^\\<\\|^\f")
  (set (make-local-variable 'version-control) 'never)
  (set (make-local-variable 'version-control) 'never)
  (set (make-local-variable 'adaptive-fill-regexp) "\\s *")
  (set (make-local-variable 'adaptive-fill-regexp) "\\s *")
  (set (make-local-variable 'font-lock-defaults)
  (set (make-local-variable 'font-lock-defaults)
       '(change-log-font-lock-keywords t))
       '(change-log-font-lock-keywords t))
  (run-hooks 'change-log-mode-hook))
  (run-hooks 'change-log-mode-hook))
 
 
;; It might be nice to have a general feature to replace this.  The idea I
;; It might be nice to have a general feature to replace this.  The idea I
;; have is a variable giving a regexp matching text which should not be
;; have is a variable giving a regexp matching text which should not be
;; moved from bol by filling.  change-log-mode would set this to "^\\s *\\s(".
;; moved from bol by filling.  change-log-mode would set this to "^\\s *\\s(".
;; But I don't feel up to implementing that today.
;; But I don't feel up to implementing that today.
(defun change-log-fill-paragraph (&optional justify)
(defun change-log-fill-paragraph (&optional justify)
  "Fill the paragraph, but preserve open parentheses at beginning of lines.
  "Fill the paragraph, but preserve open parentheses at beginning of lines.
Prefix arg means justify as well."
Prefix arg means justify as well."
  (interactive "P")
  (interactive "P")
  (let ((end (save-excursion (forward-paragraph) (point)))
  (let ((end (save-excursion (forward-paragraph) (point)))
        (beg (save-excursion (backward-paragraph)(point)))
        (beg (save-excursion (backward-paragraph)(point)))
        (paragraph-start (concat paragraph-start "\\|\\s *\\s(")))
        (paragraph-start (concat paragraph-start "\\|\\s *\\s(")))
    (fill-region beg end justify)))
    (fill-region beg end justify)))


(defvar add-log-current-defun-header-regexp
(defvar add-log-current-defun-header-regexp
  "^\\([A-Z][A-Z_ ]*[A-Z_]\\|[-_a-zA-Z]+\\)[ \t]*[:=]"
  "^\\([A-Z][A-Z_ ]*[A-Z_]\\|[-_a-zA-Z]+\\)[ \t]*[:=]"
  "*Heuristic regexp used by `add-log-current-defun' for unknown major modes.")
  "*Heuristic regexp used by `add-log-current-defun' for unknown major modes.")
 
 
;;;###autoload
;;;###autoload
(defun add-log-current-defun ()
(defun add-log-current-defun ()
  "Return name of function definition point is in, or nil.
  "Return name of function definition point is in, or nil.
 
 
Understands C, Lisp, LaTeX (\"functions\" are chapters, sections, ...),
Understands C, Lisp, LaTeX (\"functions\" are chapters, sections, ...),
Texinfo (@node titles), Perl, and Fortran.
Texinfo (@node titles), Perl, and Fortran.
 
 
Other modes are handled by a heuristic that looks in the 10K before
Other modes are handled by a heuristic that looks in the 10K before
point for uppercase headings starting in the first column or
point for uppercase headings starting in the first column or
identifiers followed by `:' or `=', see variable
identifiers followed by `:' or `=', see variable
`add-log-current-defun-header-regexp'.
`add-log-current-defun-header-regexp'.
 
 
Has a preference of looking backwards."
Has a preference of looking backwards."
  (condition-case nil
  (condition-case nil
      (save-excursion
      (save-excursion
        (let ((location (point)))
        (let ((location (point)))
          (cond ((memq major-mode '(emacs-lisp-mode lisp-mode scheme-mode
          (cond ((memq major-mode '(emacs-lisp-mode lisp-mode scheme-mode
                                                    lisp-interaction-mode))
                                                    lisp-interaction-mode))
                 ;; If we are now precisely at the beginning of a defun,
                 ;; If we are now precisely at the beginning of a defun,
                 ;; make sure beginning-of-defun finds that one
                 ;; make sure beginning-of-defun finds that one
                 ;; rather than the previous one.
                 ;; rather than the previous one.
                 (or (eobp) (forward-char 1))
                 (or (eobp) (forward-char 1))
                 (beginning-of-defun)
                 (beginning-of-defun)
                 ;; Make sure we are really inside the defun found, not after it.
                 ;; Make sure we are really inside the defun found, not after it.
                 (if (and (looking-at "\\s(")
                 (if (and (looking-at "\\s(")
                          (progn (end-of-defun)
                          (progn (end-of-defun)
                                 (< location (point)))
                                 (< location (point)))
                          (progn (forward-sexp -1)
                          (progn (forward-sexp -1)
                                 (>= location (point))))
                                 (>= location (point))))
                     (progn
                     (progn
                       (if (looking-at "\\s(")
                       (if (looking-at "\\s(")
                           (forward-char 1))
                           (forward-char 1))
                       (forward-sexp 1)
                       (forward-sexp 1)
                       (skip-chars-forward " '")
                       (skip-chars-forward " '")
                       (buffer-substring (point)
                       (buffer-substring (point)
                                         (progn (forward-sexp 1) (point))))))
                                         (progn (forward-sexp 1) (point))))))
                ((and (memq major-mode '(c-mode c++-mode c++-c-mode objc-mode))
                ((and (memq major-mode '(c-mode c++-mode c++-c-mode objc-mode))
                      (save-excursion (beginning-of-line)
                      (save-excursion (beginning-of-line)
                                      ;; Use eq instead of = here to avoid
                                      ;; Use eq instead of = here to avoid
                                      ;; error when at bob and char-after
                                      ;; error when at bob and char-after
                                      ;; returns nil.
                                      ;; returns nil.
                                      (while (eq (char-after (- (point) 2)) ?\\)
                                      (while (eq (char-after (- (point) 2)) ?\\)
                                        (forward-line -1))
                                        (forward-line -1))
                                      (looking-at "[ \t]*#[ \t]*define[ \t]")))
                                      (looking-at "[ \t]*#[ \t]*define[ \t]")))
                 ;; Handle a C macro definition.
                 ;; Handle a C macro definition.
                 (beginning-of-line)
                 (beginning-of-line)
                 (while (eq (char-after (- (point) 2)) ?\\) ;not =; note above
                 (while (eq (char-after (- (point) 2)) ?\\) ;not =; note above
                   (forward-line -1))
                   (forward-line -1))
                 (search-forward "define")
                 (search-forward "define")
                 (skip-chars-forward " \t")
                 (skip-chars-forward " \t")
                 (buffer-substring (point)
                 (buffer-substring (point)
                                   (progn (forward-sexp 1) (point))))
                                   (progn (forward-sexp 1) (point))))
                ((memq major-mode '(c-mode c++-mode c++-c-mode objc-mode))
                ((memq major-mode '(c-mode c++-mode c++-c-mode objc-mode))
                 (beginning-of-line)
                 (beginning-of-line)
                 ;; See if we are in the beginning part of a function,
                 ;; See if we are in the beginning part of a function,
                 ;; before the open brace.  If so, advance forward.
                 ;; before the open brace.  If so, advance forward.
                 (while (not (looking-at "{\\|\\(\\s *$\\)"))
                 (while (not (looking-at "{\\|\\(\\s *$\\)"))
                   (forward-line 1))
                   (forward-line 1))
                 (or (eobp)
                 (or (eobp)
                     (forward-char 1))
                     (forward-char 1))
                 (beginning-of-defun)
                 (beginning-of-defun)
                 (if (progn (end-of-defun)
                 (if (progn (end-of-defun)
                            (< location (point)))
                            (< location (point)))
                     (progn
                     (progn
                       (backward-sexp 1)
                       (backward-sexp 1)
                       (let (beg tem)
                       (let (beg tem)
 
 
                         (forward-line -1)
                         (forward-line -1)
                         ;; Skip back over typedefs of arglist.
                         ;; Skip back over typedefs of arglist.
                         (while (and (not (bobp))
                         (while (and (not (bobp))
                                     (looking-at "[ \t\n]"))
                                     (looking-at "[ \t\n]"))
                           (forward-line -1))
                           (forward-line -1))
                         ;; See if this is using the DEFUN macro used in Emacs,
                         ;; See if this is using the DEFUN macro used in Emacs,
                         ;; or the DEFUN macro used by the C library.
                         ;; or the DEFUN macro used by the C library.
                         (if (condition-case nil
                         (if (condition-case nil
                                 (and (save-excursion
                                 (and (save-excursion
                                        (end-of-line)
                                        (end-of-line)
                                        (while (= (preceding-char) ?\\)
                                        (while (= (preceding-char) ?\\)
                                          (end-of-line 2))
                                          (end-of-line 2))
                                        (backward-sexp 1)
                                        (backward-sexp 1)
                                        (beginning-of-line)
                                        (beginning-of-line)
                                        (setq tem (point))
                                        (setq tem (point))
                                        (looking-at "DEFUN\\b"))
                                        (looking-at "DEFUN\\b"))
                                      (>= location tem))
                                      (>= location tem))
                               (error nil))
                               (error nil))
                             (progn
                             (progn
                               (goto-char tem)
                               (goto-char tem)
                               (down-list 1)
                               (down-list 1)
                               (if (= (char-after (point)) ?\")
                               (if (= (char-after (point)) ?\")
                                   (progn
                                   (progn
                                     (forward-sexp 1)
                                     (forward-sexp 1)
                                     (skip-chars-forward " ,")))
                                     (skip-chars-forward " ,")))
                               (buffer-substring (point)
                               (buffer-substring (point)
                                                 (progn (forward-sexp 1) (point))))
                                                 (progn (forward-sexp 1) (point))))
                           (if (looking-at "^[+-]")
                           (if (looking-at "^[+-]")
                               (get-method-definition)
                               (get-method-definition)
                             ;; Ordinary C function syntax.
                             ;; Ordinary C function syntax.
                             (setq beg (point))
                             (setq beg (point))
                             (if (and (condition-case nil
                             (if (and (condition-case nil
                                          ;; Protect against "Unbalanced parens" error.
                                          ;; Protect against "Unbalanced parens" error.
                                          (progn
                                          (progn
                                            (down-list 1) ; into arglist
                                            (down-list 1) ; into arglist
                                            (backward-up-list 1)
                                            (backward-up-list 1)
                                            (skip-chars-backward " \t")
                                            (skip-chars-backward " \t")
                                            t)
                                            t)
                                        (error nil))
                                        (error nil))
                                      ;; Verify initial pos was after
                                      ;; Verify initial pos was after
                                      ;; real start of function.
                                      ;; real start of function.
                                      (save-excursion
                                      (save-excursion
                                        (goto-char beg)
                                        (goto-char beg)
                                        ;; For this purpose, include the line
                                        ;; For this purpose, include the line
                                        ;; that has the decl keywords.  This
                                        ;; that has the decl keywords.  This
                                        ;; may also include some of the
                                        ;; may also include some of the
                                        ;; comments before the function.
                                        ;; comments before the function.
                                        (while (and (not (bobp))
                                        (while (and (not (bobp))
                                                    (save-excursion
                                                    (save-excursion
                                                      (forward-line -1)
                                                      (forward-line -1)
                                                      (looking-at "[^\n\f]")))
                                                      (looking-at "[^\n\f]")))
                                          (forward-line -1))
                                          (forward-line -1))
                                        (>= location (point)))
                                        (>= location (point)))
                                          ;; Consistency check: going down and up
                                          ;; Consistency check: going down and up
                                          ;; shouldn't take us back before BEG.
                                          ;; shouldn't take us back before BEG.
                                          (> (point) beg))
                                          (> (point) beg))
                                 (let (end middle)
                                 (let (end middle)
                                   ;; Don't include any final newline
                                   ;; Don't include any final newline
                                   ;; in the name we use.
                                   ;; in the name we use.
                                   (if (= (preceding-char) ?\n)
                                   (if (= (preceding-char) ?\n)
                                       (forward-char -1))
                                       (forward-char -1))
                                   (setq end (point))
                                   (setq end (point))
                                   (backward-sexp 1)
                                   (backward-sexp 1)
                                   ;; Now find the right beginning of the name.
                                   ;; Now find the right beginning of the name.
                                   ;; Include certain keywords if they
                                   ;; Include certain keywords if they
                                   ;; precede the name.
                                   ;; precede the name.
                                   (setq middle (point))
                                   (setq middle (point))
                                   (forward-word -1)
                                   (forward-word -1)
                                   ;; Ignore these subparts of a class decl
                                   ;; Ignore these subparts of a class decl
                                   ;; and move back to the class name itself.
                                   ;; and move back to the class name itself.
                                   (while (looking-at "public \\|private ")
                                   (while (looking-at "public \\|private ")
                                     (skip-chars-backward " \t:")
                                     (skip-chars-backward " \t:")
                                     (setq end (point))
                                     (setq end (point))
                                     (backward-sexp 1)
                                     (backward-sexp 1)
                                     (setq middle (point))
                                     (setq middle (point))
                                     (forward-word -1))
                                     (forward-word -1))
                                   (and (bolp)
                                   (and (bolp)
                                        (looking-at "struct \\|union \\|class ")
                                        (looking-at "struct \\|union \\|class ")
                                        (setq middle (point)))
                                        (setq middle (point)))
                                   (buffer-substring middle end)))))))))
                                   (buffer-substring middle end)))))))))
                ((memq major-mode
                ((memq major-mode
                       '(TeX-mode plain-TeX-mode LaTeX-mode;; tex-mode.el
                       '(TeX-mode plain-TeX-mode LaTeX-mode;; tex-mode.el
                                  plain-tex-mode latex-mode;; cmutex.el
                                  plain-tex-mode latex-mode;; cmutex.el
                                  ))
                                  ))
                 (if (re-search-backward
                 (if (re-search-backward
                      "\\\\\\(sub\\)*\\(section\\|paragraph\\|chapter\\)" nil t)
                      "\\\\\\(sub\\)*\\(section\\|paragraph\\|chapter\\)" nil t)
                     (progn
                     (progn
                       (goto-char (match-beginning 0))
                       (goto-char (match-beginning 0))
                       (buffer-substring (1+ (point));; without initial backslash
                       (buffer-substring (1+ (point));; without initial backslash
                                         (progn
                                         (progn
                                           (end-of-line)
                                           (end-of-line)
                                           (point))))))
                                           (point))))))
                ((eq major-mode 'texinfo-mode)
                ((eq major-mode 'texinfo-mode)
                 (if (re-search-backward "^@node[ \t]+\\([^,\n]+\\)" nil t)
                 (if (re-search-backward "^@node[ \t]+\\([^,\n]+\\)" nil t)
                     (buffer-substring (match-beginning 1)
                     (buffer-substring (match-beginning 1)
                                       (match-end 1))))
                                       (match-end 1))))
                ((eq major-mode 'perl-mode)
                ((eq major-mode 'perl-mode)
                 (if (re-search-backward "^sub[ \t]+\\([^ \t\n]+\\)" nil t)
                 (if (re-search-backward "^sub[ \t]+\\([^ \t\n]+\\)" nil t)
                     (buffer-substring (match-beginning 1)
                     (buffer-substring (match-beginning 1)
                                       (match-end 1))))
                                       (match-end 1))))
                ((eq major-mode 'fortran-mode)
                ((eq major-mode 'fortran-mode)
                 ;; must be inside function body for this to work
                 ;; must be inside function body for this to work
                 (beginning-of-fortran-subprogram)
                 (beginning-of-fortran-subprogram)
                 (let ((case-fold-search t)) ; case-insensitive
                 (let ((case-fold-search t)) ; case-insensitive
                   ;; search for fortran subprogram start
                   ;; search for fortran subprogram start
                   (if (re-search-forward
                   (if (re-search-forward
                         "^[ \t]*\\(program\\|subroutine\\|function\
                         "^[ \t]*\\(program\\|subroutine\\|function\
\\|[ \ta-z0-9*]*[ \t]+function\\)"
\\|[ \ta-z0-9*]*[ \t]+function\\)"
                         nil t)
                         nil t)
                       (progn
                       (progn
                         ;; move to EOL or before first left paren
                         ;; move to EOL or before first left paren
                         (if (re-search-forward "[(\n]" nil t)
                         (if (re-search-forward "[(\n]" nil t)
                             (progn (forward-char -1)
                             (progn (forward-char -1)
                                    (skip-chars-backward " \t"))
                                    (skip-chars-backward " \t"))
                           (end-of-line))
                           (end-of-line))
                         ;; Use the name preceding that.
                         ;; Use the name preceding that.
                         (buffer-substring (point)
                         (buffer-substring (point)
                                           (progn (forward-sexp -1)
                                           (progn (forward-sexp -1)
                                                  (point)))))))
                                                  (point)))))))
                (t
                (t
                 ;; If all else fails, try heuristics
                 ;; If all else fails, try heuristics
                 (let (case-fold-search)
                 (let (case-fold-search)
                   (end-of-line)
                   (end-of-line)
                   (if (re-search-backward add-log-current-defun-header-regexp
                   (if (re-search-backward add-log-current-defun-header-regexp
                                           (- (point) 10000)
                                           (- (point) 10000)
                                           t)
                                           t)
                       (buffer-substring (match-beginning 1)
                       (buffer-substring (match-beginning 1)
                                         (match-end 1))))))))
                                         (match-end 1))))))))
    (error nil)))
    (error nil)))
 
 
(defvar get-method-definition-md)
(defvar get-method-definition-md)
 
 
;; Subroutine used within get-method-definition.
;; Subroutine used within get-method-definition.
;; Add the last match in the buffer to the end of `md',
;; Add the last match in the buffer to the end of `md',
;; followed by the string END; move to the end of that match.
;; followed by the string END; move to the end of that match.
(defun get-method-definition-1 (end)
(defun get-method-definition-1 (end)
  (setq get-method-definition-md
  (setq get-method-definition-md
        (concat get-method-definition-md
        (concat get-method-definition-md
                (buffer-substring (match-beginning 1) (match-end 1))
                (buffer-substring (match-beginning 1) (match-end 1))
                end))
                end))
  (goto-char (match-end 0)))
  (goto-char (match-end 0)))
 
 
;; For objective C, return the method name if we are in a method.
;; For objective C, return the method name if we are in a method.
(defun get-method-definition ()
(defun get-method-definition ()
  (let ((get-method-definition-md "["))
  (let ((get-method-definition-md "["))
    (save-excursion
    (save-excursion
      (if (re-search-backward "^@implementation\\s-*\\([A-Za-z_]*\\)" nil t)
      (if (re-search-backward "^@implementation\\s-*\\([A-Za-z_]*\\)" nil t)
          (get-method-definition-1 " ")))
          (get-method-definition-1 " ")))
    (save-excursion
    (save-excursion
      (cond
      (cond
       ((re-search-forward "^\\([-+]\\)[ \t\n\f\r]*\\(([^)]*)\\)?\\s-*" nil t)
       ((re-search-forward "^\\([-+]\\)[ \t\n\f\r]*\\(([^)]*)\\)?\\s-*" nil t)
        (get-method-definition-1 "")
        (get-method-definition-1 "")
        (while (not (looking-at "[{;]"))
        (while (not (looking-at "[{;]"))
          (looking-at
          (looking-at
           "\\([A-Za-z_]*:?\\)\\s-*\\(([^)]*)\\)?[A-Za-z_]*[ \t\n\f\r]*")
           "\\([A-Za-z_]*:?\\)\\s-*\\(([^)]*)\\)?[A-Za-z_]*[ \t\n\f\r]*")
          (get-method-definition-1 ""))
          (get-method-definition-1 ""))
        (concat get-method-definition-md "]"))))))
        (concat get-method-definition-md "]"))))))
 
 
 
 
(provide 'add-log)
(provide 'add-log)
 
 
;;; add-log.el ends here
;;; add-log.el ends here
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.