[Uml-devel] branches/work/isi-umbrello/scripts/kde-emacs
Thibault Normand
thibault.normand at gmail.com
Thu Dec 7 19:31:14 UTC 2006
SVN commit 611351 by tnormand:
#MERGE Trunk(611343) kdesdk/isi-umbrello
M +1 -0 kde-emacs-bindings.el
M +9 -2 kde-emacs-general.el
M +67 -18 kde-emacs-utils.el
--- branches/work/isi-umbrello/scripts/kde-emacs/kde-emacs-bindings.el #611350:611351
@@ -128,6 +128,7 @@
(define-key c++-mode-map [(f6)] 'kde-switch-cpp-h)
(define-key c-mode-map [(f6)] 'kde-switch-cpp-h)
(define-key c++-mode-map [(f7)] 'switch-to-function-def)
+(define-key c-mode-map [(f7)] 'switch-to-function-def)
(define-key c++-mode-map [(f9)] 'agulbra-make-member)
(define-key c-mode-map [(f9)] 'agulbra-make-member)
(define-key global-map [(meta n)] 'next-error)
--- branches/work/isi-umbrello/scripts/kde-emacs/kde-emacs-general.el #611350:611351
@@ -38,6 +38,13 @@
)
)
+;; Helper for kde-file-get-cpp-h
+(defun kde-file-or-buffer-exists (path)
+ "Returns true if \"filename\" is an existing file, or an open buffer"
+ (or (file-readable-p path)
+ (get-file-buffer path))
+)
+
(defun kde-file-get-cpp-h ()
"Function returns a corresponding source or header file. The returned
variable is a list of the form (FILENAME IS_READABLE) e.g. when being in
@@ -55,14 +62,14 @@
(setq listit kde-source-files)
(while (and listit (not ret)) ; loop over the list but stop once ret is set
(setq path (concat nname "." (car listit)))
- (if (file-readable-p path)
+ (if (kde-file-or-buffer-exists path)
(setq ret (cons path t))
)
(if (not ret)
(if (string-match "_p$" nname)
(progn
(setq path (concat (substring nname 0 (string-match "_p$" nname)) "." (car listit)))
- (if (file-readable-p path)
+ (if (kde-file-or-buffer-exists path)
(setq ret (cons path t))
)))
)
--- branches/work/isi-umbrello/scripts/kde-emacs/kde-emacs-utils.el #611350:611351
@@ -63,6 +63,26 @@
found)
)
+; Helper function for getting the baseclass of the current class - in a C++ header file
+; Only supports single inheritance
+(defun baseclass-under-point ()
+ (let ((pos (c-safe-scan-lists (point) -1 1)))
+ (save-excursion
+ (goto-char (if pos pos (point-min)))
+ (backward-word 2) ; move back over "public baseclass"
+ (if (looking-at "public\\|protected\\|private\s*")
+ (progn
+ (forward-word)
+ (while (looking-at "[ \t]")
+ (forward-char 1))
+ (let ((start (point)))
+ (forward-word)
+ (buffer-substring start (point))))
+ nil
+ )))
+ )
+
+
; Helper function for parsing our current position in a C++ header file
; returns (namespace (class function)) where (a b) is a cons.
(defun method-under-point ()
@@ -211,8 +231,9 @@
;(progn
; (let ((pos (kde-scan-lists (point) -1 1 nil t))) ; Go up a level
; (goto-char (if pos (+ pos 1) (point-min))))
- (let ((a (fume-function-before-point)))
- (and (string-match "^\\(.*\\)::\\(.*\\)$" a)
+ (let ((a (fume-function-before-point))
+ (functionregexp ""))
+ (if (string-match "^\\(.*\\)::\\(.*\\)$" a)
(progn
(setq class (match-string 1 a))
(setq function (match-string 2 a))
@@ -221,20 +242,34 @@
; Look for beginning of class ("\\s-+" means whitespace including newlines)
(re-search-forward
(concat "\\(class\\|struct\\|namespace\\)\\s-+"
- "\\([A-Z_]+_EXPORT[A-Z_]*\\)?\\s-+" ; allow for optional EXPORT macro
+ "\\([A-Z_]+_EXPORT[A-Z_]*\\s-+\\)?" ; allow for optional EXPORT macro
class "\\b" ; the classname - with word separator
"[^;]+{" ; the optional inheritance and the '{'
- ) nil t)
+ ) nil t) ; no error, just return nil if not found
+
+ ; Look for function - with \\b prepended, unless this is about ~Foo.
+ (setq functionregexp (kde-function-regexp-quote function))
+ (and (not (string-match "^~" functionregexp))
+ (setq functionregexp (concat "\\b" functionregexp)))
;; TODO keep looking, until we find a match that's not inside a comment
- (re-search-forward (concat "\\b" (kde-function-regexp-quote function) "[ \t]*(") nil t)))))
+ (re-search-forward (concat functionregexp "[ \t]*(") nil t))
+ ; else: not a member method, maybe just a c function
+ (progn
+ (setq function a)
+ (kde-switch-cpp-h)
+ (goto-char 0)
+ (re-search-forward (concat "\\b" (kde-function-regexp-quote function) "[ \t]*(") nil t))
+ )
+ )
+ )
(if (string-match "\\.h$" n)
(progn
(let ((mup (method-under-point))
(sig "")
(pos 0))
(setq namespace (car mup))
- (setq class (car (cdr mup)))
- (setq function (cdr (cdr mup)))
+ (setq class (cadr mup))
+ (setq function (cddr mup))
(kde-switch-cpp-h)
;; First search with namespace prefixed
@@ -270,14 +305,27 @@
(let* (
(mup (method-under-point))
(namespace (car mup)) ; will contain A::B::
- (class (car (cdr mup)))
- (function (cdr (cdr mup)))
+ (class (cadr mup))
+ (function (cddr mup))
(file (buffer-file-name))
(insertion-string (kde-function-impl-sig namespace class function))
+ (function-sig (canonical-function-sig function))
(msubstr nil)
(start nil)
(newcppfile nil)
+ (baseclass nil)
)
+ ; First, assemble the skeleton text into insertion-string
+ ; At this point it already contains the method signature
+
+ ; If constructor: add call to base class
+ (and (stringp class)
+ (string-match (concat "^ *" class "[ \\t]*(") function-sig) ; constructor
+ (setq baseclass (baseclass-under-point))
+ ; TODO: passing the parent parameter if baseclass starts with Q :)
+ (setq insertion-string (concat insertion-string "\n : " baseclass "()" )))
+
+ ; Method body
(setq insertion-string
(concat insertion-string "\n{\n"
(replace-in-string kde-make-member-default-impl "FUNCTION"
@@ -285,7 +333,8 @@
(replace-in-string insertion-string "\n" " " t)
t)
"}\n"))
- ; move to next method, to be ready for next call
+
+ ; Move to next method, to be ready for next call
(backward-char) ; in case we're after the ';'
(re-search-forward ";" nil t) ; end of this method decl
(let ((moveToNext t))
@@ -302,30 +351,30 @@
)
)
- (setq newcppfile (not (cdr (kde-file-get-cpp-h))))
+ ; Switch to .cpp if the declaration was in a header file
(if (member (file-name-extension file) kde-header-files)
(kde-switch-cpp-h)
)
+ ;(setq newcppfile (= (point-max) 1))
(goto-char (point-max))
(kde-comments-begin)
(kde-skip-blank-lines)
(setq msubstr (buffer-substring (point-at-bol) (point-at-eol)))
- (if (string-match "^#include.*moc.*" msubstr)
+ (if (string-match "^#include.*moc.*" msubstr) ; TODO refine regexp
(progn
(forward-line -1)
(end-of-line)
- (insert "\n")))
- (if (string-match "}" msubstr)
- (progn
+ (insert "\n"))
+ ; else
+ (progn
(end-of-line)
(insert "\n")
(forward-line 1)
))
- (when newcppfile
- (insert "\n"))
(insert insertion-string)
(forward-char -3)
- (c-indent-defun)
+ (c-indent-defun)
+ ; Insert #include for the header if necessary
(save-excursion
(and (string-match ".*/" file)
(setq file (replace-match "" t nil file)))
More information about the umbrello-devel
mailing list