aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Mackenzie2008-04-02 21:22:40 +0000
committerAlan Mackenzie2008-04-02 21:22:40 +0000
commit221fcdaa907e26adbdd2300bc8fc8179c0653002 (patch)
tree9a0b197b579ed0362190b32304305f30889cb8e7
parent1464a281eac2066991951fd024d7180af79bd97b (diff)
downloademacs-221fcdaa907e26adbdd2300bc8fc8179c0653002.tar.gz
emacs-221fcdaa907e26adbdd2300bc8fc8179c0653002.zip
(add-log-current-defun): Move the functionality which gets the current
function name for C like modes to cc-cmds.el, thus optimising for speed.
-rw-r--r--lisp/add-log.el163
1 files changed, 3 insertions, 160 deletions
diff --git a/lisp/add-log.el b/lisp/add-log.el
index c9fdb34bc9a..8803e764d82 100644
--- a/lisp/add-log.el
+++ b/lisp/add-log.el
@@ -914,167 +914,10 @@ Has a preference of looking backwards."
914 (buffer-substring-no-properties (point) 914 (buffer-substring-no-properties (point)
915 (progn (forward-sexp 1) 915 (progn (forward-sexp 1)
916 (point))))) 916 (point)))))
917 ((and (apply 'derived-mode-p add-log-c-like-modes)
918 (save-excursion
919 (beginning-of-line)
920 ;; Use eq instead of = here to avoid
921 ;; error when at bob and char-after
922 ;; returns nil.
923 (while (eq (char-after (- (point) 2)) ?\\)
924 (forward-line -1))
925 (looking-at "[ \t]*#[ \t]*define[ \t]")))
926 ;; Handle a C macro definition.
927 (beginning-of-line)
928 (while (eq (char-after (- (point) 2)) ?\\) ;not =; note above
929 (forward-line -1))
930 (search-forward "define")
931 (skip-chars-forward " \t")
932 (buffer-substring-no-properties (point)
933 (progn (forward-sexp 1)
934 (point))))
935 ((apply 'derived-mode-p add-log-c-like-modes) 917 ((apply 'derived-mode-p add-log-c-like-modes)
936 ;; See whether the point is inside a defun. 918 (or (c-cpp-define-name)
937 (let (having-previous-defun 919 (c-defun-name)))
938 having-next-defun 920 ((memq major-mode add-log-tex-like-modes)
939 previous-defun-end
940 next-defun-beginning)
941
942 (save-excursion
943 (setq having-previous-defun
944 (c-beginning-of-defun))
945 (c-end-of-defun)
946 ;; `c-end-of-defun' moves point to the line after
947 ;; the function close, but the position we prefer
948 ;; here is the position after the final }.
949 (backward-sexp 1)
950 (forward-sexp 1)
951 ;; Skip the semicolon ``;'' for
952 ;; enum/union/struct/class definition.
953 (if (= (char-after (point)) ?\;)
954 (forward-char 1))
955 (setq previous-defun-end (point)))
956
957 (save-excursion
958 (setq having-next-defun
959 (c-end-of-defun))
960 (c-beginning-of-defun)
961 (setq next-defun-beginning (point)))
962
963 (if (and having-next-defun
964 (< location next-defun-beginning))
965 (skip-syntax-forward " "))
966 (if (and having-previous-defun
967 (> location previous-defun-end))
968 (skip-syntax-backward " "))
969 (unless (or
970 ;; When there is no previous defun, the
971 ;; point is not in a defun if it is not at
972 ;; the beginning of the next defun.
973 (and (not having-previous-defun)
974 (not (= (point)
975 next-defun-beginning)))
976 ;; When there is no next defun, the point
977 ;; is not in a defun if it is not at the
978 ;; end of the previous defun.
979 (and (not having-next-defun)
980 (not (= (point)
981 previous-defun-end)))
982 ;; If the point is between two defuns, it
983 ;; is not in a defun.
984 (and (> (point) previous-defun-end)
985 (< (point) next-defun-beginning)))
986 ;; If the point is already at the beginning of a
987 ;; defun, there is no need to move point again.
988 (if (not (= (point) next-defun-beginning))
989 (c-beginning-of-defun))
990 ;; Is this a DEFUN construct? And is LOCATION in it?
991 (if (and (looking-at "DEFUN\\b")
992 (>= location (point)))
993 ;; DEFUN ("file-name-directory", Ffile_name_directory, Sfile_name_directory, ...) ==> Ffile_name_directory
994 ;; DEFUN(POSIX::STREAM-LOCK, stream lockp &key BLOCK SHARED START LENGTH) ==> POSIX::STREAM-LOCK
995 (progn
996 (down-list 1)
997 (when (= (char-after (point)) ?\")
998 (forward-sexp 1)
999 (search-forward ","))
1000 (skip-syntax-forward " ")
1001 (buffer-substring-no-properties
1002 (point)
1003 (progn (search-forward ",")
1004 (forward-char -1)
1005 (skip-syntax-backward " ")
1006 (point))))
1007 (if (looking-at "^[+-]")
1008 ;; Objective-C
1009 (change-log-get-method-definition)
1010 ;; Ordinary C function syntax.
1011 (let ((beg (point)))
1012 (if (and
1013 ;; Protect against "Unbalanced parens" error.
1014 (condition-case nil
1015 (progn
1016 (down-list 1) ; into arglist
1017 (backward-up-list 1)
1018 (skip-chars-backward " \t")
1019 t)
1020 (error nil))
1021 ;; Verify initial pos was after
1022 ;; real start of function.
1023 (save-excursion
1024 (goto-char beg)
1025 ;; For this purpose, include the line
1026 ;; that has the decl keywords. This
1027 ;; may also include some of the
1028 ;; comments before the function.
1029 (while (and (not (bobp))
1030 (save-excursion
1031 (forward-line -1)
1032 (looking-at "[^\n\f]")))
1033 (forward-line -1))
1034 (>= location (point)))
1035 ;; Consistency check: going down and up
1036 ;; shouldn't take us back before BEG.
1037 (> (point) beg))
1038 (let (end middle)
1039 ;; Don't include any final whitespace
1040 ;; in the name we use.
1041 (skip-chars-backward " \t\n")
1042 (setq end (point))
1043 (backward-sexp 1)
1044 ;; Now find the right beginning of the name.
1045 ;; Include certain keywords if they
1046 ;; precede the name.
1047 (setq middle (point))
1048 ;; We tried calling `forward-sexp' in a loop
1049 ;; but it causes inconsistency for C names.
1050 (forward-sexp -1)
1051 ;; Is this C++ method?
1052 (when (and (< 2 middle)
1053 (string= (buffer-substring (- middle 2)
1054 middle)
1055 "::"))
1056 ;; Include "classname::".
1057 (setq middle (point)))
1058 ;; Ignore these subparts of a class decl
1059 ;; and move back to the class name itself.
1060 (while (looking-at "public \\|private ")
1061 (skip-chars-backward " \t:")
1062 (setq end (point))
1063 (backward-sexp 1)
1064 (setq middle (point))
1065 (forward-word -1))
1066 (and (bolp)
1067 (looking-at
1068 "enum \\|struct \\|union \\|class ")
1069 (setq middle (point)))
1070 (goto-char end)
1071 (when (eq (preceding-char) ?=)
1072 (forward-char -1)
1073 (skip-chars-backward " \t")
1074 (setq end (point)))
1075 (buffer-substring-no-properties
1076 middle end)))))))))
1077 ((apply 'derived-mode-p add-log-tex-like-modes)
1078 (if (re-search-backward 921 (if (re-search-backward
1079 "\\\\\\(sub\\)*\\(section\\|paragraph\\|chapter\\)" 922 "\\\\\\(sub\\)*\\(section\\|paragraph\\|chapter\\)"
1080 nil t) 923 nil t)