(get-method-definition): Fix regexps.
[bpt/emacs.git] / lisp / add-log.el
index b2074ef..57ff522 100644 (file)
@@ -44,16 +44,23 @@ This defaults to the value returned by the `user-full-name' function.")
 This defaults to the value of `user-mail-address'.")
 
 (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.
     ("\(\\([^)\n]+\\)\)" 1 font-lock-keyword-face))    ; Function name.
   "Additional expressions to highlight in Change Log mode.")
 
+(defvar change-log-mode-map nil
+  "Keymap for Change Log major mode.")
+(if change-log-mode-map
+    nil
+  (setq change-log-mode-map (make-sparse-keymap))
+  (define-key change-log-mode-map "\M-q" 'change-log-fill-paragraph))
+
 (defun change-log-name ()
   (or change-log-default-name
       (if (eq system-type 'vax-vms) 
          "$CHANGE_LOG$.TXT" 
-       (if (eq system-type 'ms-dos)
+       (if (or (eq system-type 'ms-dos) (eq system-type 'windows-nt))
            "changelo"
          "ChangeLog"))))
 
@@ -70,16 +77,22 @@ This defaults to the value of `user-mail-address'.")
   "Find a change log file for \\[add-change-log-entry] and return the name.
 
 Optional arg FILE-NAME specifies the file to use.
-If FILE-NAME is nil, use the value of `change-log-default-name' if non-nil.
-Otherwise, search in the current directory and its successive parents
-for a file named `ChangeLog' (or whatever we use on this operating system).
+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'
+\(or whatever we use on this operating system).
+
+If 'change-log-default-name' contains a leading directory component, then
+simply find it in the current directory.  Otherwise, search in the current 
+directory and its successive parents for a file so named.
 
 Once a file is found, `change-log-default-name' is set locally in the
 current buffer to the complete file name."
   ;; If user specified a file name or if this buffer knows which one to use,
   ;; just use that.
   (or file-name
-      (setq file-name change-log-default-name)
+      (setq file-name (and change-log-default-name
+                          (file-name-directory change-log-default-name)
+                          change-log-default-name))
       (progn
        ;; Chase links in the source file
        ;; and use the change log in the dir where it points.
@@ -265,16 +278,10 @@ Runs `change-log-mode-hook'."
   (set (make-local-variable 'page-delimiter) "^\\<\\|^\f")
   (set (make-local-variable 'version-control) 'never)
   (set (make-local-variable 'adaptive-fill-regexp) "\\s *")
-  (set (make-local-variable 'font-lock-keywords) change-log-font-lock-keywords)
+  (set (make-local-variable 'font-lock-defaults)
+       '(change-log-font-lock-keywords t))
   (run-hooks 'change-log-mode-hook))
 
-(defvar change-log-mode-map nil
-  "Keymap for Change Log major mode.")
-(if change-log-mode-map
-    nil
-  (setq change-log-mode-map (make-sparse-keymap))
-  (define-key change-log-mode-map "\M-q" 'change-log-fill-paragraph))
-
 ;; 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
 ;; moved from bol by filling.  change-log-mode would set this to "^\\s *\\s(".
@@ -326,7 +333,7 @@ Has a preference of looking backwards."
                       (skip-chars-forward " ")
                       (buffer-substring (point)
                                         (progn (forward-sexp 1) (point))))))
-               ((and (memq major-mode '(c-mode c++-mode c++-c-mode))
+               ((and (memq major-mode '(c-mode c++-mode c++-c-mode objc-mode))
                      (save-excursion (beginning-of-line)
                                      ;; Use eq instead of = here to avoid
                                      ;; error when at bob and char-after
@@ -342,7 +349,7 @@ Has a preference of looking backwards."
                 (skip-chars-forward " \t")
                 (buffer-substring (point)
                                   (progn (forward-sexp 1) (point))))
-               ((memq major-mode '(c-mode c++-mode c++-c-mode))
+               ((memq major-mode '(c-mode c++-mode c++-c-mode objc-mode))
                 (beginning-of-line)
                 ;; See if we are in the beginning part of a function,
                 ;; before the open brace.  If so, advance forward.
@@ -384,36 +391,38 @@ Has a preference of looking backwards."
                                     (skip-chars-forward " ,")))
                               (buffer-substring (point)
                                                 (progn (forward-sexp 1) (point))))
-                          ;; Ordinary C function syntax.
-                          (setq beg (point))
-                          (if (condition-case nil
-                                  ;; Protect against "Unbalanced parens" error.
-                                  (progn
-                                    (down-list 1) ; into arglist
-                                    (backward-up-list 1)
-                                    (skip-chars-backward " \t")
-                                    t)
-                                (error nil))
-                              ;; Verify initial pos was after
-                              ;; real start of function.
-                              (if (and (save-excursion
-                                         (goto-char beg)
-                                         ;; For this purpose, include the line
-                                         ;; that has the decl keywords.  This
-                                         ;; may also include some of the
-                                         ;; comments before the function.
-                                         (while (and (not (bobp))
-                                                     (save-excursion
-                                                       (forward-line -1)
-                                                       (looking-at "[^\n\f]")))
-                                           (forward-line -1))
-                                         (>= location (point)))
-                                       ;; Consistency check: going down and up
-                                       ;; shouldn't take us back before BEG.
-                                       (> (point) beg))
-                                  (buffer-substring (point)
-                                                    (progn (backward-sexp 1)
-                                                           (point))))))))))
+                           (if (looking-at "^[+-]")
+                               (get-method-definition)
+                             ;; Ordinary C function syntax.
+                             (setq beg (point))
+                             (if (condition-case nil
+                                     ;; Protect against "Unbalanced parens" error.
+                                     (progn
+                                       (down-list 1) ; into arglist
+                                       (backward-up-list 1)
+                                       (skip-chars-backward " \t")
+                                       t)
+                                   (error nil))
+                                 ;; Verify initial pos was after
+                                 ;; real start of function.
+                                 (if (and (save-excursion
+                                            (goto-char beg)
+                                            ;; For this purpose, include the line
+                                            ;; that has the decl keywords.  This
+                                            ;; may also include some of the
+                                            ;; comments before the function.
+                                            (while (and (not (bobp))
+                                                        (save-excursion
+                                                          (forward-line -1)
+                                                          (looking-at "[^\n\f]")))
+                                              (forward-line -1))
+                                            (>= location (point)))
+                                          ;; Consistency check: going down and up
+                                          ;; shouldn't take us back before BEG.
+                                          (> (point) beg))
+                                     (buffer-substring (point)
+                                                       (progn (backward-sexp 1)
+                                                              (point)))))))))))
                ((memq major-mode
                       '(TeX-mode plain-TeX-mode LaTeX-mode;; tex-mode.el
                                  plain-tex-mode latex-mode;; cmutex.el
@@ -427,7 +436,7 @@ Has a preference of looking backwards."
                                           (end-of-line)
                                           (point))))))
                ((eq major-mode 'texinfo-mode)
-                (if (re-search-backward "^@node[ \t]+\\([^,]+\\)," nil t)
+                (if (re-search-backward "^@node[ \t]+\\([^,\n]+\\)" nil t)
                     (buffer-substring (match-beginning 1)
                                       (match-end 1))))
                ((eq major-mode 'perl-mode)
@@ -464,6 +473,31 @@ Has a preference of looking backwards."
                                         (match-end 1))))))))
     (error nil)))
 
+;; Subroutine used within get-method-definition.
+;; Add the last match in the buffer to the end of `md',
+;; followed by the string END; move to the end of that match.
+(defun get-method-definition-1 (end)
+  (setq md (concat md 
+                  (buffer-substring (match-beginning 1) (match-end 1))
+                  end))
+  (goto-char (match-end 0)))
+
+;; For objective C, return the method name if we are in a method.
+(defun get-method-definition ()
+  (let ((md "["))
+    (save-excursion
+      (if (re-search-backward "^@implementation\\s-*\\([A-Za-z_]*\\)" nil t)
+         (get-method-definition-1 " ")))
+    (save-excursion
+      (cond
+       ((re-search-forward "^\\([-+]\\)[ \t\n\f\r]*\\(([^)]*)\\)?\\s-*" nil t)
+       (get-method-definition-1 "")
+       (while (not (looking-at "[{;]"))
+         (looking-at
+          "\\([A-Za-z_]*:?\\)\\s-*\\(([^)]*)\\)?[A-Za-z_]*[ \t\n\f\r]*")
+         (get-method-definition-1 ""))
+       (concat md "]"))))))
+
 
 (provide 'add-log)