[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdesdk/scripts/kde-emacs
From: David Faure <faure () kde ! org>
Date: 2006-12-05 10:13:24
Message-ID: 1165313604.061030.18371.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 610737 by dfaure:
agulbra-make-member: fix too many newlines between methods, and not enough newlines \
if the cpp file only contains e.g. a #include.
Add call to base class constructor when making the skeleton for \
the constructor (and there's a base class).
kde-file-get-cpp-h: also check open buffers for unsaved files, so that we don't \
create a foo.cpp if there's a foo.cc open already
M +9 -2 kde-emacs-general.el
M +47 -13 kde-emacs-utils.el
--- trunk/KDE/kdesdk/scripts/kde-emacs/kde-emacs-general.el #610736:610737
@@ -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))
)))
)
--- trunk/KDE/kdesdk/scripts/kde-emacs/kde-emacs-utils.el #610736:610737
@@ -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 ()
@@ -233,8 +253,8 @@
(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 +290,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 +318,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 +336,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)))
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic