Warning, /sdk/kde-dev-scripts/kde-devel-emacs.el is written in an unsupported language. File is not indexed.
0001 ;; -*- emacs-lisp -*- 0002 0003 ; To use this file, add this to your .emacs, uncommented : 0004 ;(load "cc-engine.elc") 0005 ;(load "~/kde2/kdesdk/scripts/kde-devel-emacs.el") 0006 ; (setq auto-mode-alist 0007 ; (append '(("\\.h$" . c++-mode)) auto-mode-alist)) 0008 0009 0010 ; Tip: also add (gnuserv-start), to be able to use gnuclient to open new files from a shell 0011 0012 ; Add (setq magic-keys-mode t) to your .xemacs/init.el or ~/.emacs (before loading this file) 0013 ; to enable the magic keys in C++ mode (auto-insertion of spaces and newlines). 0014 0015 ; See the end of this file for the list of key bindings and for customizing them 0016 0017 ; This file is maintained by David Faure <faure@kde.org> 0018 0019 0020 ; Global variables used to differentiate between different emacs 0021 ; versions : 0022 ; emacs - t if GNU/Emacs is used 0023 ; xemacs - t if XEmacs is being used 0024 0025 (if (string= (substring (emacs-version) 0 6) "XEmacs") 0026 (progn 0027 (setq emacs nil) 0028 (setq xemacs t)) 0029 (progn 0030 (setq emacs t) 0031 (setq xemacs nil))) 0032 0033 0034 ;; ------- First part, from Arnt's "c++ stuff" 0035 0036 (defun agulbra-c++-tab (arg) 0037 "Do the right thing about tabs in c++ mode" 0038 (interactive "*P") 0039 (cond 0040 ((and (not (looking-at "[A-Za-z0-9]")) 0041 (save-excursion 0042 (forward-char -1) 0043 (looking-at "[A-Za-z0-9:>_\\-\\&\\.(){}\\*\\+/]"))) 0044 (dabbrev-expand arg)) 0045 (t 0046 (save-excursion 0047 (beginning-of-line) 0048 (c-indent-command))))) 0049 0050 (defun agulbra-clean-out-spaces () 0051 "Remove spaces at ends of lines" 0052 (interactive) 0053 (and (not buffer-read-only) 0054 (save-excursion 0055 (goto-char (point-min)) 0056 (let ((count 0) 0057 (bmp (buffer-modified-p))) 0058 (while (re-search-forward "[ \t]+$" nil t) 0059 (setq count (1+ count)) 0060 (replace-match "" t t)) 0061 (set-buffer-modified-p bmp) 0062 (and (buffer-modified-p) 0063 (basic-save-buffer)))))) 0064 0065 ; the above used to contain (untabify (point-min) (point-max)) too 0066 0067 ;; it seems that recursion in agulbra-clean-out-spaces trashes Gnu/Emacs stack 0068 ;; one of the functions in there has to behave differently than its XEmacs 0069 ;; counterpart does, if you're reading this in a middle of may 2002 then 0070 ;; please email me (Zack) at zackrat@att.net and bug me to finally fix this 0071 (defun agulbra-c++-clean-out-spaces () 0072 "Remove spaces at ends of lines, only in c++ mode" 0073 (interactive) 0074 (and (eq major-mode 'c++-mode) 0075 (if xemacs 0076 (agulbra-clean-out-spaces) 0077 ))) 0078 0079 (add-hook 'find-file-hooks 'agulbra-c++-clean-out-spaces) 0080 (add-hook 'write-file-hooks 'agulbra-c++-clean-out-spaces) 0081 0082 (defun agulbra-delete-into-nomenclature (&optional arg) 0083 "Delete forward until the end of a nomenclature section or word. 0084 With arg, to it arg times." 0085 (interactive "p") 0086 (save-excursion 0087 (let ((b (point-marker))) 0088 (c-forward-into-nomenclature arg) 0089 (delete-region b (point-marker))))) 0090 0091 0092 (setq c++-mode-hook 0093 (lambda () 0094 (font-lock-mode) 0095 (c-set-style "stroustrup") 0096 (setq c-tab-always-indent nil 0097 insert-tab-mode nil 0098 indent-tabs-mode nil 0099 fume-auto-rescan-buffer-p nil 0100 c-basic-offset 4 0101 c-access-key "\\<\\(signals\\|k_dcop\\|\\(public\\|protected\\|private\\)\\([ ]+slots\\)?\\)\\>:" 0102 c-hanging-comment-ender-p nil 0103 c-offsets-alist (append '((case-label . 0) 0104 (access-label . -) 0105 (label . 0) 0106 (statement-cont . c-lineup-math) 0107 ) c-offsets-alist)) 0108 (cond ((string-match "^\\(.*/qt/src\\)/.*/" buffer-file-truename) 0109 (progn 0110 (make-local-variable 'compile-command) 0111 (setq compile-command 0112 (concat "make -k -j 3 -C " 0113 (substring buffer-file-truename 0114 (match-beginning 1) (match-end 1)) 0115 " GNUmakefile.debug && make -k -j 3 -C " 0116 (substring buffer-file-truename 0117 (match-beginning 1) (match-end 1)) 0118 " -f GNUmakefile.debug")))) 0119 ((string-match "^\\\(.*/2x/src\\\)/.*/" buffer-file-truename) 0120 (progn 0121 (make-local-variable 'compile-command) 0122 (setq compile-command 0123 (concat "make -k -C " 0124 (substring buffer-file-truename 0125 (match-beginning 1) 0126 (match-end 1))))))) 0127 (define-key c++-mode-map "\C-m" 'newline-and-indent) 0128 (define-key c++-mode-map "\C-i" 'agulbra-c++-tab) 0129 (define-key c++-mode-map "\ef" 'c-forward-into-nomenclature) 0130 (define-key c++-mode-map "\ed" 'agulbra-delete-into-nomenclature) 0131 (define-key c++-mode-map "\eb" 'c-backward-into-nomenclature) 0132 0133 ; Add (setq magic-keys-mode t) to your .emacs (before loading this file) 0134 ; to enable the magic keys in C++ mode. 0135 (and (boundp 'magic-keys-mode) 0136 (progn 0137 (define-key c++-mode-map [\(] 'insert-parens) 0138 (define-key c++-mode-map [\)] 'insert-parens2) 0139 (define-key c++-mode-map [,] 'insert-comma) 0140 (define-key c++-mode-map [\{] 'insert-curly-brace) 0141 )) 0142 )) 0143 0144 (setq c-mode-hook 0145 (lambda () 0146 (font-lock-mode) 0147 (setq c-tab-always-indent nil 0148 c-basic-offset 4 0149 c-offsets-alist (append '((case-label . 4) 0150 (access-label . -) 0151 (label . 0) 0152 (statement-cont . c-lineup-math) 0153 ) c-offsets-alist)))) 0154 0155 0156 (defun agulbra-make-member () 0157 "make a skeleton member function in the .cpp or .cc file" 0158 (interactive) 0159 (let ((class nil) 0160 (function nil) 0161 (file (buffer-file-name)) 0162 (insertion-string nil) 0163 (start nil)) 0164 (save-excursion 0165 (and (re-search-backward "^class[ \t]" nil t) 0166 (progn 0167 (forward-word 1) 0168 (while (looking-at "[ \t]*Q_EXPORT") 0169 (forward-word 2)) 0170 (while (looking-at "[ \t]") 0171 (forward-char 1)) 0172 (setq start (point)) 0173 (while (looking-at "[A-Za-z0-9_]") 0174 (forward-char 1)) 0175 (setq class (buffer-substring start (point)))))) 0176 (progn 0177 (and (looking-at "$") 0178 (progn 0179 (search-backward ")" nil t) 0180 (forward-char) 0181 (backward-sexp))) 0182 (and (stringp class) 0183 (re-search-backward "^[ \t]") 0184 (progn 0185 (while (looking-at "[ \t]") 0186 (forward-char 1)) 0187 (setq start (point)) 0188 (and (search-forward "(" nil t) 0189 (progn 0190 (forward-char -1) 0191 (forward-sexp))) 0192 (and (looking-at "[ \t]+const") 0193 (forward-word 1)) 0194 (and (looking-at ";") 0195 (setq function (buffer-substring start (point)))) 0196 (re-search-forward "(" nil t)))) 0197 (and (stringp function) 0198 (progn ;; get rid of virtual, static, multiple spaces, default values. 0199 (and (string-match "[ \t]*\\<virtual\\>[ \t]*" function) 0200 (setq function (replace-match " " t t function))) 0201 (and (string-match "^\\(virtual\\>\\)?[ \t]*" function) 0202 (setq function (replace-match "" t t function))) 0203 (and (string-match "^\\(static\\>\\)?[ \t]*" function) 0204 (setq function (replace-match "" t t function))) 0205 (while (string-match " +" function) 0206 (setq function (replace-match " " t t function))) 0207 (while (string-match "\t+" function) 0208 (setq function (replace-match " " t t function))) 0209 (while (string-match " ?=[^,)]+" function) 0210 (setq function (replace-match " " t t function))) 0211 (while (string-match " +," function) 0212 (setq function (replace-match "," t t function))))) 0213 (and (stringp function) 0214 (stringp class) 0215 (stringp file) 0216 (progn 0217 (cond ((string-match (concat "^ *" class "[ \\t]*(") function) 0218 (progn 0219 (setq insertion-string 0220 (concat 0221 (replace-match 0222 (concat class "::" class "(") 0223 t t function) 0224 "\n{\n \n}\n")))) 0225 ((string-match (concat "^ *~" class "[ \\t]*(") function) 0226 (progn 0227 (setq insertion-string 0228 (concat 0229 (replace-match 0230 (concat class "::~" class "(") 0231 t t function) 0232 "\n{\n \n}\n")))) 0233 ((string-match " *\\([a-zA-Z0-9_]+\\)[ \\t]*(" function) 0234 (progn 0235 (setq insertion-string 0236 (concat 0237 (replace-match 0238 (concat " " class "::" "\\1(") 0239 t nil function) 0240 "\n{\n \n}\n")))) 0241 (t 0242 (error (concat "Can't parse declaration ``" 0243 function "'' in class ``" class 0244 "'', aborting")))) 0245 (stringp insertion-string)) 0246 (string-match "\\.h$" file) 0247 (setq f (replace-match ".cpp" t t file)) 0248 (if (file-readable-p f ) 0249 (message "") 0250 (progn 0251 (string-match "\\.h$" file) 0252 (setq f (replace-match ".cc" t t file)) 0253 )) 0254 (find-file f) 0255 (progn 0256 (goto-char (point-max)) 0257 (insert insertion-string) 0258 (forward-char -3) 0259 (save-excursion 0260 (and (string-match ".*/" file) 0261 (setq file (replace-match "" t nil file))) 0262 (or (re-search-backward 0263 (concat "^#include *\"" file "\"$") nil t) 0264 (progn 0265 (goto-char (point-min)) 0266 (re-search-forward "^$" nil t) 0267 (insert "\n#include \"" file "\"\n"))))))) 0268 (fume-rescan-buffer) 0269 ) 0270 0271 0272 (setq compilation-error-regexp-systems-list '(gnu of comma 4bsd) 0273 compilation-ask-about-save nil) 0274 0275 0276 (defun c-guess-basic-syntax () 0277 (save-excursion 0278 (save-restriction 0279 (beginning-of-line) 0280 (let* ((indent-point (point)) 0281 (case-fold-search nil) 0282 (fullstate (c-parse-state)) 0283 (state fullstate) 0284 literal containing-sexp char-before-ip char-after-ip lim 0285 syntax placeholder c-in-literal-cache inswitch-p 0286 tmpsymbol keyword injava-inher special-brace-list 0287 ;; narrow out any enclosing class or extern "C" block 0288 (inclass-p (c-narrow-out-enclosing-class state indent-point)) 0289 inenclosing-p) 0290 ;; check for meta top-level enclosing constructs, possible 0291 ;; extern language definitions, possibly (in C++) namespace 0292 ;; definitions. 0293 (save-excursion 0294 (save-restriction 0295 (widen) 0296 (if (and inclass-p 0297 (progn 0298 (goto-char (aref inclass-p 0)) 0299 (looking-at (concat c-extra-toplevel-key "[^_]")))) 0300 (let ((enclosing (match-string 1))) 0301 (cond 0302 ((string-equal enclosing "extern") 0303 (setq inenclosing-p 'extern)) 0304 ((string-equal enclosing "namespace") 0305 (setq inenclosing-p 'namespace)) 0306 ))))) 0307 ;; get the buffer position of the most nested opening brace, 0308 ;; if there is one, and it hasn't been narrowed out 0309 (save-excursion 0310 (goto-char indent-point) 0311 (skip-chars-forward " \t}") 0312 (skip-chars-backward " \t") 0313 (while (and state 0314 (not containing-sexp)) 0315 (setq containing-sexp (car state) 0316 state (cdr state)) 0317 (if (consp containing-sexp) 0318 ;; if cdr == point, then containing sexp is the brace 0319 ;; that opens the sexp we close 0320 (if (= (cdr containing-sexp) (point)) 0321 (setq containing-sexp (car containing-sexp)) 0322 ;; otherwise, ignore this element 0323 (setq containing-sexp nil)) 0324 ;; ignore the bufpos if its been narrowed out by the 0325 ;; containing class or does not contain the indent point 0326 (if (or (<= containing-sexp (point-min)) 0327 (>= containing-sexp indent-point)) 0328 (setq containing-sexp nil))))) 0329 0330 ;; set the limit on the farthest back we need to search 0331 (setq lim (or containing-sexp 0332 (if (consp (car fullstate)) 0333 (cdr (car fullstate)) 0334 nil) 0335 (point-min))) 0336 0337 ;; cache char before and after indent point, and move point to 0338 ;; the most likely position to perform the majority of tests 0339 (goto-char indent-point) 0340 (skip-chars-forward " \t") 0341 (setq char-after-ip (char-after)) 0342 (c-backward-syntactic-ws lim) 0343 (setq char-before-ip (char-before)) 0344 (goto-char indent-point) 0345 (skip-chars-forward " \t") 0346 0347 ;; are we in a literal? 0348 (setq literal (c-in-literal lim)) 0349 0350 ;; now figure out syntactic qualities of the current line 0351 (cond 0352 ;; CASE 1: in a string. 0353 ((memq literal '(string)) 0354 (c-add-syntax 'string (c-point 'bopl))) 0355 ;; CASE 2: in a C or C++ style comment. 0356 ((memq literal '(c c++)) 0357 (c-add-syntax literal (car (c-literal-limits lim)))) 0358 ;; CASE 3: in a cpp preprocessor macro continuation. 0359 ((and (eq literal 'pound) 0360 (/= (save-excursion 0361 (c-beginning-of-macro lim) 0362 (setq placeholder (point))) 0363 (c-point 'boi))) 0364 (c-add-syntax 'cpp-macro-cont placeholder)) 0365 ;; CASE 4: In-expression statement. 0366 ((and (or c-inexpr-class-key c-inexpr-block-key c-lambda-key) 0367 (setq placeholder (c-looking-at-inexpr-block))) 0368 (setq tmpsymbol (assq (car placeholder) 0369 '((inexpr-class . class-open) 0370 (inexpr-statement . block-open)))) 0371 (if tmpsymbol 0372 ;; It's a statement block or an anonymous class. 0373 (setq tmpsymbol (cdr tmpsymbol)) 0374 ;; It's a Pike lambda. Check whether we are between the 0375 ;; lambda keyword and the argument list or at the defun 0376 ;; opener. 0377 (setq tmpsymbol (if (eq char-after-ip ?{) 0378 'inline-open 0379 'lambda-intro-cont))) 0380 (goto-char (cdr placeholder)) 0381 (back-to-indentation) 0382 (c-add-syntax tmpsymbol (point)) 0383 (unless (eq (point) (cdr placeholder)) 0384 (c-add-syntax (car placeholder)))) 0385 ;; CASE 5: Line is at top level. 0386 ((null containing-sexp) 0387 (cond 0388 ;; CASE 5A: we are looking at a defun, brace list, class, 0389 ;; or inline-inclass method opening brace 0390 ((setq special-brace-list 0391 (or (and c-special-brace-lists 0392 (c-looking-at-special-brace-list)) 0393 (eq char-after-ip ?{))) 0394 (cond 0395 ;; CASE 5A.1: extern language or namespace construct 0396 ((save-excursion 0397 (goto-char indent-point) 0398 (skip-chars-forward " \t") 0399 (and (c-safe (progn (c-backward-sexp 2) t)) 0400 (looking-at (concat c-extra-toplevel-key "[^_]")) 0401 (setq keyword (match-string 1) 0402 placeholder (point)) 0403 (or (and (string-equal keyword "namespace") 0404 (setq tmpsymbol 'namespace-open)) 0405 (and (string-equal keyword "extern") 0406 (progn 0407 (c-forward-sexp 1) 0408 (c-forward-syntactic-ws) 0409 (eq (char-after) ?\")) 0410 (setq tmpsymbol 'extern-lang-open))) 0411 )) 0412 (goto-char placeholder) 0413 (c-add-syntax tmpsymbol (c-point 'boi))) 0414 ;; CASE 5A.2: we are looking at a class opening brace 0415 ((save-excursion 0416 (goto-char indent-point) 0417 (skip-chars-forward " \t{") 0418 ;; TBD: watch out! there could be a bogus 0419 ;; c-state-cache in place when we get here. we have 0420 ;; to go through much chicanery to ignore the cache. 0421 ;; But of course, there may not be! BLECH! BOGUS! 0422 (let ((decl 0423 (let ((c-state-cache nil)) 0424 (c-search-uplist-for-classkey (c-parse-state)) 0425 ))) 0426 (and decl 0427 (setq placeholder (aref decl 0))) 0428 )) 0429 (c-add-syntax 'class-open placeholder)) 0430 ;; CASE 5A.3: brace list open 0431 ((save-excursion 0432 (c-beginning-of-statement-1 lim) 0433 ;; c-b-o-s could have left us at point-min 0434 (and (bobp) 0435 (c-forward-syntactic-ws indent-point)) 0436 (if (looking-at "typedef[^_]") 0437 (progn (c-forward-sexp 1) 0438 (c-forward-syntactic-ws indent-point))) 0439 (setq placeholder (c-point 'boi)) 0440 (or (consp special-brace-list) 0441 (and (or (save-excursion 0442 (goto-char indent-point) 0443 (setq tmpsymbol nil) 0444 (while (and (> (point) placeholder) 0445 (= (c-backward-token-1 1 t) 0) 0446 (/= (char-after) ?=)) 0447 (if (and (not tmpsymbol) 0448 (looking-at "new\\>[^_]")) 0449 (setq tmpsymbol 'topmost-intro-cont))) 0450 (eq (char-after) ?=)) 0451 (looking-at "enum[ \t\n]+")) 0452 (save-excursion 0453 (while (and (< (point) indent-point) 0454 (= (c-forward-token-1 1 t) 0) 0455 (not (memq (char-after) '(?\; ?\())))) 0456 (not (memq (char-after) '(?\; ?\())) 0457 )))) 0458 (if (and (c-major-mode-is 'java-mode) 0459 (eq tmpsymbol 'topmost-intro-cont)) 0460 ;; We're in Java and have found that the open brace 0461 ;; belongs to a "new Foo[]" initialization list, 0462 ;; which means the brace list is part of an 0463 ;; expression and not a top level definition. We 0464 ;; therefore treat it as any topmost continuation 0465 ;; even though the semantically correct symbol still 0466 ;; is brace-list-open, on the same grounds as in 0467 ;; case 10B.2. 0468 (progn 0469 (c-beginning-of-statement-1 lim) 0470 (c-forward-syntactic-ws) 0471 (c-add-syntax 'topmost-intro-cont (c-point 'boi))) 0472 (c-add-syntax 'brace-list-open placeholder))) 0473 ;; CASE 5A.4: inline defun open 0474 ((and inclass-p (not inenclosing-p)) 0475 (c-add-syntax 'inline-open) 0476 (c-add-class-syntax 'inclass inclass-p)) 0477 ;; CASE 5A.5: ordinary defun open 0478 (t 0479 (goto-char placeholder) 0480 (if inclass-p 0481 (c-add-syntax 'defun-open (c-point 'boi)) 0482 (c-add-syntax 'defun-open (c-point 'bol))) 0483 ))) 0484 ;; CASE 5B: first K&R arg decl or member init 0485 ((c-just-after-func-arglist-p) 0486 (cond 0487 ;; CASE 5B.1: a member init 0488 ((or (eq char-before-ip ?:) 0489 (eq char-after-ip ?:)) 0490 ;; this line should be indented relative to the beginning 0491 ;; of indentation for the topmost-intro line that contains 0492 ;; the prototype's open paren 0493 ;; TBD: is the following redundant? 0494 (if (eq char-before-ip ?:) 0495 (forward-char -1)) 0496 (c-backward-syntactic-ws lim) 0497 ;; TBD: is the preceding redundant? 0498 (if (eq (char-before) ?:) 0499 (progn (forward-char -1) 0500 (c-backward-syntactic-ws lim))) 0501 (if (eq (char-before) ?\)) 0502 (c-backward-sexp 1)) 0503 (setq placeholder (point)) 0504 (save-excursion 0505 (and (c-safe (c-backward-sexp 1) t) 0506 (looking-at "throw[^_]") 0507 (c-safe (c-backward-sexp 1) t) 0508 (setq placeholder (point)))) 0509 (goto-char placeholder) 0510 (c-add-syntax 'member-init-intro (c-point 'boi)) 0511 ;; we don't need to add any class offset since this 0512 ;; should be relative to the ctor's indentation 0513 ) 0514 ;; CASE 5B.2: K&R arg decl intro 0515 (c-recognize-knr-p 0516 (c-add-syntax 'knr-argdecl-intro (c-point 'boi)) 0517 (if inclass-p (c-add-class-syntax 'inclass inclass-p))) 0518 ;; CASE 5B.3: Inside a member init list. 0519 ((c-beginning-of-member-init-list lim) 0520 (c-forward-syntactic-ws) 0521 (c-add-syntax 'member-init-cont (point))) 0522 ;; CASE 5B.4: Nether region after a C++ or Java func 0523 ;; decl, which could include a `throws' declaration. 0524 (t 0525 (c-beginning-of-statement-1 lim) 0526 (c-add-syntax 'func-decl-cont (c-point 'boi)) 0527 ))) 0528 ;; CASE 5C: inheritance line. could be first inheritance 0529 ;; line, or continuation of a multiple inheritance 0530 ((or (and c-baseclass-key 0531 (progn 0532 (when (eq char-after-ip ?,) 0533 (skip-chars-forward " \t") 0534 (forward-char)) 0535 (looking-at c-baseclass-key))) 0536 (and (or (eq char-before-ip ?:) 0537 ;; watch out for scope operator 0538 (save-excursion 0539 (and (eq char-after-ip ?:) 0540 (c-safe (progn (forward-char 1) t)) 0541 (not (eq (char-after) ?:)) 0542 ))) 0543 (save-excursion 0544 (c-backward-syntactic-ws lim) 0545 (if (eq char-before-ip ?:) 0546 (progn 0547 (forward-char -1) 0548 (c-backward-syntactic-ws lim))) 0549 (back-to-indentation) 0550 (looking-at c-class-key))) 0551 ;; for Java 0552 (and (c-major-mode-is 'java-mode) 0553 (let ((fence (save-excursion 0554 (c-beginning-of-statement-1 lim) 0555 (point))) 0556 cont done) 0557 (save-excursion 0558 (while (not done) 0559 (cond ((looking-at c-Java-special-key) 0560 (setq injava-inher (cons cont (point)) 0561 done t)) 0562 ((or (not (c-safe (c-forward-sexp -1) t)) 0563 (<= (point) fence)) 0564 (setq done t)) 0565 ) 0566 (setq cont t))) 0567 injava-inher) 0568 (not (c-crosses-statement-barrier-p (cdr injava-inher) 0569 (point))) 0570 )) 0571 (cond 0572 ;; CASE 5C.1: non-hanging colon on an inher intro 0573 ((eq char-after-ip ?:) 0574 (c-backward-syntactic-ws lim) 0575 (c-add-syntax 'inher-intro (c-point 'boi)) 0576 ;; don't add inclass symbol since relative point already 0577 ;; contains any class offset 0578 ) 0579 ;; CASE 5C.2: hanging colon on an inher intro 0580 ((eq char-before-ip ?:) 0581 (c-add-syntax 'inher-intro (c-point 'boi)) 0582 (if inclass-p (c-add-class-syntax 'inclass inclass-p))) 0583 ;; CASE agulbrahack.1: 0584 ((and inclass-p 0585 c-access-key 0586 (looking-at c-access-key)) 0587 (c-add-syntax 'access-label (c-point 'bonl)) 0588 ) 0589 ;; CASE 5C.3: in a Java implements/extends 0590 (injava-inher 0591 (let ((where (cdr injava-inher)) 0592 (cont (car injava-inher))) 0593 (goto-char where) 0594 (cond ((looking-at "throws[ \t\n]") 0595 (c-add-syntax 'func-decl-cont 0596 (progn (c-beginning-of-statement-1 lim) 0597 (c-point 'boi)))) 0598 (cont (c-add-syntax 'inher-cont where)) 0599 (t (c-add-syntax 'inher-intro 0600 (progn (goto-char (cdr injava-inher)) 0601 (c-beginning-of-statement-1 lim) 0602 (point)))) 0603 ))) 0604 ;; CASE 5C.4: a continued inheritance line 0605 (t 0606 (c-beginning-of-inheritance-list lim) 0607 (c-add-syntax 'inher-cont (point)) 0608 ;; don't add inclass symbol since relative point already 0609 ;; contains any class offset 0610 ))) 0611 ;; CASE 5D: this could be a top-level compound statement, a 0612 ;; member init list continuation, or a template argument 0613 ;; list continuation. 0614 ((c-with-syntax-table (if (c-major-mode-is 'c++-mode) 0615 c++-template-syntax-table 0616 (syntax-table)) 0617 (save-excursion 0618 (while (and (= (c-backward-token-1 1 t lim) 0) 0619 (not (looking-at "[;{<,]")))) 0620 (eq (char-after) ?,))) 0621 (goto-char indent-point) 0622 (c-beginning-of-member-init-list lim) 0623 (cond 0624 ;; CASE 5D.1: hanging member init colon, but watch out 0625 ;; for bogus matches on access specifiers inside classes. 0626 ((and (save-excursion 0627 (setq placeholder (point)) 0628 (c-backward-token-1 1 t lim) 0629 (and (eq (char-after) ?:) 0630 (not (eq (char-before) ?:)))) 0631 (save-excursion 0632 (goto-char placeholder) 0633 (back-to-indentation) 0634 (or 0635 (/= (car (save-excursion 0636 (parse-partial-sexp (point) placeholder))) 0637 0) 0638 (and 0639 (if c-access-key (not (looking-at c-access-key)) t) 0640 (not (looking-at c-class-key)) 0641 (if c-bitfield-key (not (looking-at c-bitfield-key)) t)) 0642 ))) 0643 (goto-char placeholder) 0644 (c-forward-syntactic-ws) 0645 (c-add-syntax 'member-init-cont (point)) 0646 ;; we do not need to add class offset since relative 0647 ;; point is the member init above us 0648 ) 0649 ;; CASE 5D.2: non-hanging member init colon 0650 ((progn 0651 (c-forward-syntactic-ws indent-point) 0652 (eq (char-after) ?:)) 0653 (skip-chars-forward " \t:") 0654 (c-add-syntax 'member-init-cont (point))) 0655 ;; CASE 5D.3: perhaps a multiple inheritance line? 0656 ((save-excursion 0657 (c-beginning-of-statement-1 lim) 0658 (setq placeholder (point)) 0659 (looking-at c-inher-key)) 0660 (goto-char placeholder) 0661 (c-add-syntax 'inher-cont (c-point 'boi))) 0662 ;; CASE 5D.4: perhaps a template list continuation? 0663 ((save-excursion 0664 (goto-char indent-point) 0665 (skip-chars-backward "^<" lim) 0666 ;; not sure if this is the right test, but it should 0667 ;; be fast and mostly accurate. 0668 (setq placeholder (point)) 0669 (and (eq (char-before) ?<) 0670 (not (c-in-literal lim)))) 0671 ;; we can probably indent it just like an arglist-cont 0672 (goto-char placeholder) 0673 (c-beginning-of-statement-1 lim) 0674 (c-add-syntax 'template-args-cont (c-point 'boi))) 0675 ;; CASE 5D.5: perhaps a top-level statement-cont 0676 (t 0677 (c-beginning-of-statement-1 lim) 0678 ;; skip over any access-specifiers 0679 (and inclass-p c-access-key 0680 (while (looking-at c-access-key) 0681 (forward-line 1))) 0682 ;; skip over comments, whitespace 0683 (c-forward-syntactic-ws indent-point) 0684 (c-add-syntax 'statement-cont (c-point 'boi))) 0685 )) 0686 ;; CASE 5E: we are looking at a access specifier 0687 ((and inclass-p 0688 c-access-key 0689 (looking-at c-access-key)) 0690 (c-add-syntax 'access-label (c-point 'bonl)) 0691 (c-add-class-syntax 'inclass inclass-p)) 0692 ;; CASE 5F: extern-lang-close or namespace-close? 0693 ((and inenclosing-p 0694 (eq char-after-ip ?})) 0695 (setq tmpsymbol (if (eq inenclosing-p 'extern) 0696 'extern-lang-close 0697 'namespace-close)) 0698 (c-add-syntax tmpsymbol (aref inclass-p 0))) 0699 ;; CASE 5G: we are looking at the brace which closes the 0700 ;; enclosing nested class decl 0701 ((and inclass-p 0702 (eq char-after-ip ?}) 0703 (save-excursion 0704 (save-restriction 0705 (widen) 0706 (forward-char 1) 0707 (and (c-safe (progn (c-backward-sexp 1) t)) 0708 (= (point) (aref inclass-p 1)) 0709 )))) 0710 (c-add-class-syntax 'class-close inclass-p)) 0711 ;; CASE 5H: we could be looking at subsequent knr-argdecls 0712 ((and c-recognize-knr-p 0713 ;; here we essentially use the hack that is used in 0714 ;; Emacs' c-mode.el to limit how far back we should 0715 ;; look. The assumption is made that argdecls are 0716 ;; indented at least one space and that function 0717 ;; headers are not indented. 0718 (let ((limit (save-excursion 0719 (re-search-backward "^[^ \^L\t\n#]" nil 'move) 0720 (point)))) 0721 (save-excursion 0722 (c-backward-syntactic-ws limit) 0723 (setq placeholder (point)) 0724 (while (and (memq (char-before) '(?\; ?,)) 0725 (> (point) limit)) 0726 (beginning-of-line) 0727 (setq placeholder (point)) 0728 (c-backward-syntactic-ws limit)) 0729 (and (eq (char-before) ?\)) 0730 (or (not c-method-key) 0731 (progn 0732 (c-forward-sexp -1) 0733 (forward-char -1) 0734 (c-backward-syntactic-ws) 0735 (not (or (memq (char-before) '(?- ?+)) 0736 ;; or a class category 0737 (progn 0738 (c-forward-sexp -2) 0739 (looking-at c-class-key)) 0740 ))))) 0741 )) 0742 (save-excursion 0743 (c-beginning-of-statement-1) 0744 (not (looking-at "typedef[ \t\n]+")))) 0745 (goto-char placeholder) 0746 (c-add-syntax 'knr-argdecl (c-point 'boi))) 0747 ;; CASE 5I: ObjC method definition. 0748 ((and c-method-key 0749 (looking-at c-method-key)) 0750 (c-add-syntax 'objc-method-intro (c-point 'boi))) 0751 ;; CASE 5J: we are at the topmost level, make sure we skip 0752 ;; back past any access specifiers 0753 ((progn 0754 (c-backward-syntactic-ws lim) 0755 (while (and inclass-p 0756 c-access-key 0757 (not (bobp)) 0758 (save-excursion 0759 (c-safe (progn (c-backward-sexp 1) t)) 0760 ;; agulbrahack 2 0761 (and (looking-at "slots:") 0762 (c-backward-sexp 1)) 0763 (looking-at c-access-key))) 0764 (c-backward-sexp 1) 0765 (c-backward-syntactic-ws lim)) 0766 (or (bobp) 0767 (memq (char-before) '(?\; ?\})))) 0768 ;; real beginning-of-line could be narrowed out due to 0769 ;; enclosure in a class block 0770 (save-restriction 0771 (widen) 0772 (c-add-syntax 'topmost-intro (c-point 'bol)) 0773 (if inclass-p 0774 (progn 0775 (goto-char (aref inclass-p 1)) 0776 (or (= (point) (c-point 'boi)) 0777 (goto-char (aref inclass-p 0))) 0778 (cond 0779 ((eq inenclosing-p 'extern) 0780 (c-add-syntax 'inextern-lang (c-point 'boi))) 0781 ((eq inenclosing-p 'namespace) 0782 (c-add-syntax 'innamespace (c-point 'boi))) 0783 (t (c-add-class-syntax 'inclass inclass-p))) 0784 )) 0785 )) 0786 ;; CASE 5K: we are at an ObjC or Java method definition 0787 ;; continuation line. 0788 ((and c-method-key 0789 (progn 0790 (c-beginning-of-statement-1 lim) 0791 (beginning-of-line) 0792 (looking-at c-method-key))) 0793 (c-add-syntax 'objc-method-args-cont (point))) 0794 ;; CASE 5L: we are at the first argument of a template 0795 ;; arglist that begins on the previous line. 0796 ((eq (char-before) ?<) 0797 (c-beginning-of-statement-1 lim) 0798 (c-forward-syntactic-ws) 0799 (c-add-syntax 'template-args-cont (c-point 'boi))) 0800 ;; CASE 5M: we are at a topmost continuation line 0801 (t 0802 (c-beginning-of-statement-1 lim) 0803 (c-forward-syntactic-ws) 0804 (c-add-syntax 'topmost-intro-cont (c-point 'boi))) 0805 )) ; end CASE 5 0806 ;; (CASE 6 has been removed.) 0807 ;; CASE 7: line is an expression, not a statement. Most 0808 ;; likely we are either in a function prototype or a function 0809 ;; call argument list 0810 ((not (or (and c-special-brace-lists 0811 (save-excursion 0812 (goto-char containing-sexp) 0813 (c-looking-at-special-brace-list))) 0814 (eq (char-after containing-sexp) ?{))) 0815 (c-backward-syntactic-ws containing-sexp) 0816 (cond 0817 ;; CASE 7A: we are looking at the arglist closing paren 0818 ((and (or (c-major-mode-is 'pike-mode) 0819 ;; Don't check this in Pike since it allows a 0820 ;; comma after the last arg. 0821 (not (eq char-before-ip ?,))) 0822 (memq char-after-ip '(?\) ?\]))) 0823 (goto-char containing-sexp) 0824 (setq placeholder (c-point 'boi)) 0825 (when (and (c-safe (backward-up-list 1) t) 0826 (> (point) placeholder)) 0827 (forward-char) 0828 (skip-chars-forward " \t") 0829 (setq placeholder (point))) 0830 (c-add-syntax 'arglist-close placeholder)) 0831 ;; CASE 7B: Looking at the opening brace of an 0832 ;; in-expression block or brace list. 0833 ((eq char-after-ip ?{) 0834 (goto-char indent-point) 0835 (setq placeholder (c-point 'boi)) 0836 (goto-char containing-sexp) 0837 (if (c-inside-bracelist-p placeholder 0838 (cons containing-sexp state)) 0839 (progn 0840 (c-add-syntax 'brace-list-open (c-point 'boi)) 0841 (c-add-syntax 'inexpr-class)) 0842 (c-add-syntax 'block-open (c-point 'boi)) 0843 (c-add-syntax 'inexpr-statement))) 0844 ;; CASE 7C: we are looking at the first argument in an empty 0845 ;; argument list. Use arglist-close if we're actually 0846 ;; looking at a close paren or bracket. 0847 ((memq char-before-ip '(?\( ?\[)) 0848 (goto-char containing-sexp) 0849 (setq placeholder (c-point 'boi)) 0850 (when (and (c-safe (backward-up-list 1) t) 0851 (> (point) placeholder)) 0852 (forward-char) 0853 (skip-chars-forward " \t") 0854 (setq placeholder (point))) 0855 (c-add-syntax 'arglist-intro placeholder)) 0856 ;; CASE 7D: we are inside a conditional test clause. treat 0857 ;; these things as statements 0858 ((save-excursion 0859 (goto-char containing-sexp) 0860 (and (c-safe (progn (c-forward-sexp -1) t)) 0861 (looking-at "\\<for\\>[^_]"))) 0862 (goto-char (1+ containing-sexp)) 0863 (c-forward-syntactic-ws indent-point) 0864 (c-beginning-of-statement-1 containing-sexp) 0865 (if (eq char-before-ip ?\;) 0866 (c-add-syntax 'statement (point)) 0867 (c-add-syntax 'statement-cont (point)) 0868 )) 0869 ;; CASE 7E: maybe a continued method call. This is the case 0870 ;; when we are inside a [] bracketed exp, and what precede 0871 ;; the opening bracket is not an identifier. 0872 ((and c-method-key 0873 (eq (char-after containing-sexp) ?\[) 0874 (save-excursion 0875 (goto-char (1- containing-sexp)) 0876 (c-backward-syntactic-ws (c-point 'bod)) 0877 (if (not (looking-at c-symbol-key)) 0878 (c-add-syntax 'objc-method-call-cont containing-sexp)) 0879 ))) 0880 ;; CASE 7F: we are looking at an arglist continuation line, 0881 ;; but the preceding argument is on the same line as the 0882 ;; opening paren. This case includes multi-line 0883 ;; mathematical paren groupings, but we could be on a 0884 ;; for-list continuation line 0885 ((save-excursion 0886 (goto-char (1+ containing-sexp)) 0887 (skip-chars-forward " \t") 0888 (not (eolp))) 0889 (goto-char containing-sexp) 0890 (setq placeholder (c-point 'boi)) 0891 (when (and (c-safe (backward-up-list 1) t) 0892 (> (point) placeholder)) 0893 (forward-char) 0894 (skip-chars-forward " \t") 0895 (setq placeholder (point))) 0896 (c-add-syntax 'arglist-cont-nonempty placeholder)) 0897 ;; CASE 7G: we are looking at just a normal arglist 0898 ;; continuation line 0899 (t (c-beginning-of-statement-1 containing-sexp) 0900 (forward-char 1) 0901 (c-forward-syntactic-ws indent-point) 0902 (c-add-syntax 'arglist-cont (c-point 'boi))) 0903 )) 0904 ;; CASE 8: func-local multi-inheritance line 0905 ((and c-baseclass-key 0906 (save-excursion 0907 (goto-char indent-point) 0908 (skip-chars-forward " \t") 0909 (looking-at c-baseclass-key))) 0910 (goto-char indent-point) 0911 (skip-chars-forward " \t") 0912 (cond 0913 ;; CASE 8A: non-hanging colon on an inher intro 0914 ((eq char-after-ip ?:) 0915 (c-backward-syntactic-ws lim) 0916 (c-add-syntax 'inher-intro (c-point 'boi))) 0917 ;; CASE 8B: hanging colon on an inher intro 0918 ((eq char-before-ip ?:) 0919 (c-add-syntax 'inher-intro (c-point 'boi))) 0920 ;; CASE 8C: a continued inheritance line 0921 (t 0922 (c-beginning-of-inheritance-list lim) 0923 (c-add-syntax 'inher-cont (point)) 0924 ))) 0925 ;; CASE 9: we are inside a brace-list 0926 ((setq special-brace-list 0927 (or (and c-special-brace-lists 0928 (save-excursion 0929 (goto-char containing-sexp) 0930 (c-looking-at-special-brace-list))) 0931 (c-inside-bracelist-p containing-sexp state))) 0932 (cond 0933 ;; CASE 9A: In the middle of a special brace list opener. 0934 ((and (consp special-brace-list) 0935 (save-excursion 0936 (goto-char containing-sexp) 0937 (eq (char-after) ?\()) 0938 (eq char-after-ip (car (cdr special-brace-list)))) 0939 (goto-char (car (car special-brace-list))) 0940 (skip-chars-backward " \t") 0941 (if (and (bolp) 0942 (assoc 'statement-cont 0943 (setq placeholder (c-guess-basic-syntax)))) 0944 (setq syntax placeholder) 0945 (c-beginning-of-statement-1 lim) 0946 (c-forward-token-1 0) 0947 (if (looking-at "typedef\\>") (c-forward-token-1 1)) 0948 (c-add-syntax 'brace-list-open (c-point 'boi)))) 0949 ;; CASE 9B: brace-list-close brace 0950 ((if (consp special-brace-list) 0951 ;; Check special brace list closer. 0952 (progn 0953 (goto-char (car (car special-brace-list))) 0954 (save-excursion 0955 (goto-char indent-point) 0956 (back-to-indentation) 0957 (or 0958 ;; We were between the special close char and the `)'. 0959 (and (eq (char-after) ?\)) 0960 (eq (1+ (point)) (cdr (car special-brace-list)))) 0961 ;; We were before the special close char. 0962 (and (eq (char-after) (cdr (cdr special-brace-list))) 0963 (= (c-forward-token-1) 0) 0964 (eq (1+ (point)) (cdr (car special-brace-list))))))) 0965 ;; Normal brace list check. 0966 (and (eq char-after-ip ?}) 0967 (c-safe (progn (forward-char 1) 0968 (c-backward-sexp 1) 0969 t)) 0970 (= (point) containing-sexp))) 0971 (c-add-syntax 'brace-list-close (c-point 'boi))) 0972 (t 0973 ;; Prepare for the rest of the cases below by going to the 0974 ;; token following the opening brace 0975 (if (consp special-brace-list) 0976 (progn 0977 (goto-char (car (car special-brace-list))) 0978 (c-forward-token-1 1 nil indent-point)) 0979 (goto-char containing-sexp)) 0980 (forward-char) 0981 (let ((start (point))) 0982 (c-forward-syntactic-ws indent-point) 0983 (goto-char (max start (c-point 'bol)))) 0984 (skip-chars-forward " \t\n\r" indent-point) 0985 (cond 0986 ;; CASE 9C: we're looking at the first line in a brace-list 0987 ((= (point) indent-point) 0988 (goto-char containing-sexp) 0989 (c-add-syntax 'brace-list-intro (c-point 'boi)) 0990 ) ; end CASE 9C 0991 ;; CASE 9D: this is just a later brace-list-entry or 0992 ;; brace-entry-open 0993 (t (if (or (eq char-after-ip ?{) 0994 (and c-special-brace-lists 0995 (save-excursion 0996 (goto-char indent-point) 0997 (c-forward-syntactic-ws (c-point 'eol)) 0998 (c-looking-at-special-brace-list (point))))) 0999 (c-add-syntax 'brace-entry-open (point)) 1000 (c-add-syntax 'brace-list-entry (point)) 1001 )) ; end CASE 9D 1002 )))) ; end CASE 9 1003 ;; CASE 10: A continued statement 1004 ((and (not (memq char-before-ip '(?\; ?:))) 1005 (or (not (eq char-before-ip ?})) 1006 (c-looking-at-inexpr-block-backward containing-sexp)) 1007 (> (point) 1008 (save-excursion 1009 (c-beginning-of-statement-1 containing-sexp) 1010 (c-forward-syntactic-ws) 1011 (setq placeholder (point)))) 1012 (/= placeholder containing-sexp)) 1013 (goto-char indent-point) 1014 (skip-chars-forward " \t") 1015 (let ((after-cond-placeholder 1016 (save-excursion 1017 (goto-char placeholder) 1018 (if (and c-conditional-key (looking-at c-conditional-key)) 1019 (progn 1020 (c-safe (c-skip-conditional)) 1021 (c-forward-syntactic-ws) 1022 (if (eq (char-after) ?\;) 1023 (progn 1024 (forward-char 1) 1025 (c-forward-syntactic-ws))) 1026 (point)) 1027 nil)))) 1028 (cond 1029 ;; CASE 10A: substatement 1030 ((and after-cond-placeholder 1031 (>= after-cond-placeholder indent-point)) 1032 (goto-char placeholder) 1033 (if (eq char-after-ip ?{) 1034 (c-add-syntax 'substatement-open (c-point 'boi)) 1035 (c-add-syntax 'substatement (c-point 'boi)))) 1036 ;; CASE 10B: open braces for class or brace-lists 1037 ((setq special-brace-list 1038 (or (and c-special-brace-lists 1039 (c-looking-at-special-brace-list)) 1040 (eq char-after-ip ?{))) 1041 (cond 1042 ;; CASE 10B.1: class-open 1043 ((save-excursion 1044 (goto-char indent-point) 1045 (skip-chars-forward " \t{") 1046 (let ((decl (c-search-uplist-for-classkey (c-parse-state)))) 1047 (and decl 1048 (setq placeholder (aref decl 0))) 1049 )) 1050 (c-add-syntax 'class-open placeholder)) 1051 ;; CASE 10B.2: brace-list-open 1052 ((or (consp special-brace-list) 1053 (save-excursion 1054 (goto-char placeholder) 1055 (looking-at "\\<enum\\>")) 1056 (save-excursion 1057 (goto-char indent-point) 1058 (while (and (> (point) placeholder) 1059 (= (c-backward-token-1 1 t) 0) 1060 (/= (char-after) ?=))) 1061 (eq (char-after) ?=))) 1062 ;; The most semantically accurate symbol here is 1063 ;; brace-list-open, but we report it simply as a 1064 ;; statement-cont. The reason is that one normally 1065 ;; adjusts brace-list-open for brace lists as 1066 ;; top-level constructs, and brace lists inside 1067 ;; statements is a completely different context. 1068 (goto-char indent-point) 1069 (c-beginning-of-closest-statement) 1070 (c-add-syntax 'statement-cont (c-point 'boi))) 1071 ;; CASE 10B.3: The body of a function declared inside a 1072 ;; normal block. This can only occur in Pike. 1073 ((and (c-major-mode-is 'pike-mode) 1074 (progn 1075 (goto-char indent-point) 1076 (not (c-looking-at-bos)))) 1077 (c-beginning-of-closest-statement) 1078 (c-add-syntax 'defun-open (c-point 'boi))) 1079 ;; CASE 10B.4: catch-all for unknown construct. 1080 (t 1081 ;; Can and should I add an extensibility hook here? 1082 ;; Something like c-recognize-hook so support for 1083 ;; unknown constructs could be added. It's probably a 1084 ;; losing proposition, so I dunno. 1085 (goto-char placeholder) 1086 (c-add-syntax 'statement-cont (c-point 'boi)) 1087 (c-add-syntax 'block-open)) 1088 )) 1089 ;; CASE 10C: iostream insertion or extraction operator 1090 ((looking-at "<<\\|>>") 1091 (goto-char placeholder) 1092 (and after-cond-placeholder 1093 (goto-char after-cond-placeholder)) 1094 (while (and (re-search-forward "<<\\|>>" indent-point 'move) 1095 (c-in-literal placeholder))) 1096 ;; if we ended up at indent-point, then the first 1097 ;; streamop is on a separate line. Indent the line like 1098 ;; a statement-cont instead 1099 (if (/= (point) indent-point) 1100 (c-add-syntax 'stream-op (c-point 'boi)) 1101 (c-backward-syntactic-ws lim) 1102 (c-add-syntax 'statement-cont (c-point 'boi)))) 1103 ;; CASE 10D: continued statement. find the accurate 1104 ;; beginning of statement or substatement 1105 (t 1106 (c-beginning-of-statement-1 after-cond-placeholder) 1107 ;; KLUDGE ALERT! c-beginning-of-statement-1 can leave 1108 ;; us before the lim we're passing in. It should be 1109 ;; fixed, but I'm worried about side-effects at this 1110 ;; late date. Fix for v5. 1111 (goto-char (or (and after-cond-placeholder 1112 (max after-cond-placeholder (point))) 1113 (point))) 1114 (c-add-syntax 'statement-cont (point))) 1115 ))) 1116 ;; CASE 11: an else clause? 1117 ((looking-at "\\<else\\>[^_]") 1118 (c-backward-to-start-of-if containing-sexp) 1119 (c-add-syntax 'else-clause (c-point 'boi))) 1120 ;; CASE 12: Statement. But what kind? Lets see if its a 1121 ;; while closure of a do/while construct 1122 ((progn 1123 (goto-char indent-point) 1124 (skip-chars-forward " \t") 1125 (and (looking-at "while\\b[^_]") 1126 (save-excursion 1127 (c-backward-to-start-of-do containing-sexp) 1128 (setq placeholder (point)) 1129 (looking-at "do\\b[^_]")) 1130 )) 1131 (goto-char placeholder) 1132 (c-add-syntax 'do-while-closure (c-point 'boi))) 1133 ;; CASE 13: A catch or finally clause? This case is simpler 1134 ;; than if-else and do-while, because a block is required 1135 ;; after every try, catch and finally. 1136 ((save-excursion 1137 (and (cond ((c-major-mode-is 'c++-mode) 1138 (looking-at "\\<catch\\>[^_]")) 1139 ((c-major-mode-is 'java-mode) 1140 (looking-at "\\<\\(catch\\|finally\\)\\>[^_]"))) 1141 (c-safe (c-backward-sexp) t) 1142 (eq (char-after) ?{) 1143 (c-safe (c-backward-sexp) t) 1144 (if (eq (char-after) ?\() 1145 (c-safe (c-backward-sexp) t) 1146 t) 1147 (looking-at "\\<\\(try\\|catch\\)\\>[^_]") 1148 (setq placeholder (c-point 'boi)))) 1149 (c-add-syntax 'catch-clause placeholder)) 1150 ;; CASE 14: A case or default label 1151 ((looking-at c-switch-label-key) 1152 (goto-char containing-sexp) 1153 ;; check for hanging braces 1154 (if (/= (point) (c-point 'boi)) 1155 (c-forward-sexp -1)) 1156 (c-add-syntax 'case-label (c-point 'boi))) 1157 ;; CASE 15: any other label 1158 ((looking-at c-label-key) 1159 (goto-char containing-sexp) 1160 ;; check for hanging braces 1161 (if (/= (point) (c-point 'boi)) 1162 (c-forward-sexp -1)) 1163 (c-add-syntax 'label (c-point 'boi))) 1164 ;; CASE 16: block close brace, possibly closing the defun or 1165 ;; the class 1166 ((eq char-after-ip ?}) 1167 (let* ((lim (c-safe-position containing-sexp fullstate)) 1168 (relpos (save-excursion 1169 (goto-char containing-sexp) 1170 (if (/= (point) (c-point 'boi)) 1171 (c-beginning-of-statement-1 lim)) 1172 (c-point 'boi)))) 1173 (cond 1174 ;; CASE 16A: closing a lambda defun or an in-expression 1175 ;; block? 1176 ((save-excursion 1177 (goto-char containing-sexp) 1178 (setq placeholder (c-looking-at-inexpr-block))) 1179 (setq tmpsymbol (if (eq (car placeholder) 'inlambda) 1180 'inline-close 1181 'block-close)) 1182 (goto-char containing-sexp) 1183 (back-to-indentation) 1184 (if (= containing-sexp (point)) 1185 (c-add-syntax tmpsymbol (point)) 1186 (goto-char (cdr placeholder)) 1187 (back-to-indentation) 1188 (c-add-syntax tmpsymbol (point)) 1189 (if (/= (point) (cdr placeholder)) 1190 (c-add-syntax (car placeholder))))) 1191 ;; CASE 16B: does this close an inline or a function in 1192 ;; an extern block or namespace? 1193 ((progn 1194 (goto-char containing-sexp) 1195 (setq placeholder (c-search-uplist-for-classkey state))) 1196 (goto-char (aref placeholder 0)) 1197 (if (looking-at (concat c-extra-toplevel-key "[^_]")) 1198 (c-add-syntax 'defun-close relpos) 1199 (c-add-syntax 'inline-close relpos))) 1200 ;; CASE 16C: if there an enclosing brace that hasn't 1201 ;; been narrowed out by a class, then this is a 1202 ;; block-close 1203 ((and (not inenclosing-p) 1204 (c-most-enclosing-brace state) 1205 (or (not (c-major-mode-is 'pike-mode)) 1206 ;; In Pike it can be a defun-close of a 1207 ;; function declared in a statement block. Let 1208 ;; it through to be handled below. 1209 (or (c-looking-at-bos) 1210 (progn 1211 (c-beginning-of-statement-1) 1212 (looking-at c-conditional-key))))) 1213 (c-add-syntax 'block-close relpos)) 1214 ;; CASE 16D: find out whether we're closing a top-level 1215 ;; class or a defun 1216 (t 1217 (save-restriction 1218 (narrow-to-region (point-min) indent-point) 1219 (let ((decl (c-search-uplist-for-classkey (c-parse-state)))) 1220 (if decl 1221 (c-add-class-syntax 'class-close decl) 1222 (c-add-syntax 'defun-close relpos))))) 1223 ))) 1224 ;; CASE 17: statement catchall 1225 (t 1226 ;; we know its a statement, but we need to find out if it is 1227 ;; the first statement in a block 1228 (goto-char containing-sexp) 1229 (forward-char 1) 1230 (c-forward-syntactic-ws indent-point) 1231 ;; now skip forward past any case/default clauses we might find. 1232 (while (or (c-skip-case-statement-forward fullstate indent-point) 1233 (and (looking-at c-switch-label-key) 1234 (not inswitch-p))) 1235 (setq inswitch-p t)) 1236 ;; we want to ignore non-case labels when skipping forward 1237 (while (and (looking-at c-label-key) 1238 (goto-char (match-end 0))) 1239 (c-forward-syntactic-ws indent-point)) 1240 (cond 1241 ;; CASE 17A: we are inside a case/default clause inside a 1242 ;; switch statement. find out if we are at the statement 1243 ;; just after the case/default label. 1244 ((and inswitch-p 1245 (progn 1246 (goto-char indent-point) 1247 (c-beginning-of-statement-1 containing-sexp) 1248 (setq placeholder (point)) 1249 (beginning-of-line) 1250 (when (re-search-forward c-switch-label-key 1251 (max placeholder (c-point 'eol)) t) 1252 (setq placeholder (match-beginning 0))))) 1253 (goto-char indent-point) 1254 (skip-chars-forward " \t") 1255 (if (eq (char-after) ?{) 1256 (c-add-syntax 'statement-case-open placeholder) 1257 (c-add-syntax 'statement-case-intro placeholder))) 1258 ;; CASE 17B: continued statement 1259 ((eq char-before-ip ?,) 1260 (goto-char indent-point) 1261 (c-beginning-of-closest-statement) 1262 (c-add-syntax 'statement-cont (c-point 'boi))) 1263 ;; CASE 17C: a question/colon construct? But make sure 1264 ;; what came before was not a label, and what comes after 1265 ;; is not a globally scoped function call! 1266 ((or (and (memq char-before-ip '(?: ??)) 1267 (save-excursion 1268 (goto-char indent-point) 1269 (c-backward-syntactic-ws lim) 1270 (back-to-indentation) 1271 (not (looking-at c-label-key)))) 1272 (and (memq char-after-ip '(?: ??)) 1273 (save-excursion 1274 (goto-char indent-point) 1275 (skip-chars-forward " \t") 1276 ;; watch out for scope operator 1277 (not (looking-at "::"))))) 1278 (goto-char indent-point) 1279 (c-beginning-of-closest-statement) 1280 (c-add-syntax 'statement-cont (c-point 'boi))) 1281 ;; CASE 17D: any old statement 1282 ((< (point) indent-point) 1283 (let ((safepos (c-most-enclosing-brace fullstate)) 1284 relpos done) 1285 (goto-char indent-point) 1286 (c-beginning-of-statement-1 safepos) 1287 ;; It is possible we're on the brace that opens a nested 1288 ;; function. 1289 (if (and (eq (char-after) ?{) 1290 (save-excursion 1291 (c-backward-syntactic-ws safepos) 1292 (not (eq (char-before) ?\;)))) 1293 (c-beginning-of-statement-1 safepos)) 1294 (if (and inswitch-p 1295 (looking-at c-switch-label-key)) 1296 (progn 1297 (goto-char (match-end 0)) 1298 (c-forward-syntactic-ws))) 1299 (setq relpos (c-point 'boi)) 1300 (while (and (not done) 1301 (<= safepos (point)) 1302 (/= relpos (point))) 1303 (c-beginning-of-statement-1 safepos) 1304 (if (= relpos (c-point 'boi)) 1305 (setq done t)) 1306 (setq relpos (c-point 'boi))) 1307 (c-add-syntax 'statement relpos) 1308 (if (eq char-after-ip ?{) 1309 (c-add-syntax 'block-open)))) 1310 ;; CASE 17E: first statement in an in-expression block 1311 ((setq placeholder 1312 (save-excursion 1313 (goto-char containing-sexp) 1314 (c-looking-at-inexpr-block))) 1315 (goto-char containing-sexp) 1316 (back-to-indentation) 1317 (let ((block-intro (if (eq (car placeholder) 'inlambda) 1318 'defun-block-intro 1319 'statement-block-intro))) 1320 (if (= containing-sexp (point)) 1321 (c-add-syntax block-intro (point)) 1322 (goto-char (cdr placeholder)) 1323 (back-to-indentation) 1324 (c-add-syntax block-intro (point)) 1325 (if (/= (point) (cdr placeholder)) 1326 (c-add-syntax (car placeholder))))) 1327 (if (eq char-after-ip ?{) 1328 (c-add-syntax 'block-open))) 1329 ;; CASE 17F: first statement in an inline, or first 1330 ;; statement in a top-level defun. we can tell this is it 1331 ;; if there are no enclosing braces that haven't been 1332 ;; narrowed out by a class (i.e. don't use bod here!) 1333 ((save-excursion 1334 (save-restriction 1335 (widen) 1336 (goto-char containing-sexp) 1337 (c-narrow-out-enclosing-class state containing-sexp) 1338 (not (c-most-enclosing-brace state)))) 1339 (goto-char containing-sexp) 1340 ;; if not at boi, then defun-opening braces are hung on 1341 ;; right side, so we need a different relpos 1342 (if (/= (point) (c-point 'boi)) 1343 (progn 1344 (c-backward-syntactic-ws) 1345 (c-safe (c-forward-sexp (if (eq (char-before) ?\)) 1346 -1 -2))) 1347 ;; looking at a Java throws clause following a 1348 ;; method's parameter list 1349 (c-beginning-of-statement-1) 1350 )) 1351 (c-add-syntax 'defun-block-intro (c-point 'boi))) 1352 ;; CASE 17G: First statement in a function declared inside 1353 ;; a normal block. This can only occur in Pike. 1354 ((and (c-major-mode-is 'pike-mode) 1355 (progn 1356 (goto-char containing-sexp) 1357 (and (not (c-looking-at-bos)) 1358 (progn 1359 (c-beginning-of-statement-1) 1360 (not (looking-at c-conditional-key)))))) 1361 (c-add-syntax 'defun-block-intro (c-point 'boi))) 1362 ;; CASE 17H: first statement in a block 1363 (t (goto-char containing-sexp) 1364 (if (/= (point) (c-point 'boi)) 1365 (c-beginning-of-statement-1 1366 (if (= (point) lim) 1367 (c-safe-position (point) state) lim))) 1368 (c-add-syntax 'statement-block-intro (c-point 'boi)) 1369 (if (eq char-after-ip ?{) 1370 (c-add-syntax 'block-open))) 1371 )) 1372 ) 1373 ;; now we need to look at any modifiers 1374 (goto-char indent-point) 1375 (skip-chars-forward " \t") 1376 (cond 1377 ;; are we looking at a comment only line? 1378 ((and (looking-at c-comment-start-regexp) 1379 (/= (c-forward-token-1 0 nil (c-point 'eol)) 0)) 1380 (c-add-syntax 'comment-intro)) 1381 ;; we might want to give additional offset to friends (in C++). 1382 ((and (c-major-mode-is 'c++-mode) 1383 (looking-at c-C++-friend-key)) 1384 (c-add-syntax 'friend)) 1385 ;; Start of a preprocessor directive? 1386 ((and (eq literal 'pound) 1387 (= (save-excursion 1388 (c-beginning-of-macro lim) 1389 (setq placeholder (point))) 1390 (c-point 'boi)) 1391 (not (and (c-major-mode-is 'pike-mode) 1392 (eq (char-after (1+ placeholder)) ?\")))) 1393 (c-add-syntax 'cpp-macro))) 1394 ;; return the syntax 1395 syntax)))) 1396 1397 1398 (defun agulbra-switch-cpp-h () 1399 "Switch to the corresponding .cpp, .C, .cc or .h file." 1400 (interactive) 1401 (let ((n (buffer-file-name)) 1402 (c nil)) 1403 (cond ((and (string-match "\\.h$" n) 1404 (progn 1405 (setq c (replace-match ".cpp" t t n)) 1406 (file-readable-p c))) 1407 (find-file c)) 1408 ((and (string-match "\\.h$" n) 1409 (progn 1410 (setq c (replace-match ".cc" t t n)) 1411 (file-readable-p c))) 1412 (find-file c)) 1413 ((and (string-match "\\.h$" n) 1414 (progn 1415 (setq c (replace-match ".C" t t n)) 1416 (file-readable-p c))) 1417 (find-file c)) 1418 ((string-match "\\.h$" n) 1419 (find-file (replace-match ".cpp" t t n))) 1420 ((string-match "\\.h$" n) 1421 (find-file (replace-match ".cpp" t t n))) 1422 ;((string-match "_[a-z]+[0-9]*.cpp$" n) 1423 ; (find-file (replace-match ".h" t t n))) 1424 ((string-match "\\.cpp$" n) 1425 (find-file (replace-match ".h" t t n))) 1426 ((string-match "\\.cc$" n) 1427 (find-file (replace-match ".h" t t n))) 1428 ((string-match "\\.c$" n) 1429 (find-file (replace-match ".h" t t n))) 1430 (t 1431 (error "%s is neither .h, .cc, .C or .cpp" n))))) 1432 1433 ;; ----- Second part, contrinuted by Klaralvdalens Datakonsult 1434 (defvar kdab-qt-documentation 1435 "http://doc.trolltech.com/3.0/XXX.html" 1436 "URL for Qt documentation. XXX must be in the string. 1437 Example: file:/packages/kde-src/qt-copy/doc/html/XXX.html") 1438 1439 1440 ;; special case for include files 1441 ;; Please notify blackie@klaralvdalens-datakonsult.se with any modification to this variable! 1442 (defvar kdab-special-includes 1443 '( 1444 (qlayout.h QHBoxLayout QVBoxLayout QGridLayout QBoxLayout) 1445 (qlistview.h QListViewItem QCheckListItem QListViewItemIterator) 1446 (qiconview.h QIconViewItem QIconDragItem QIconDrag) 1447 (qdragobject.h QTextDrag QStoredDrag QUriDag QColorDrag QImageDrag QDragManager) 1448 (qmime.h QMimeSource QMimeSourceFactory QWindowsMime) 1449 (qptrlist.h QPtrListIterator) 1450 (qevent.h QTimerEvent QMouseEvent QWheelEvent QTabletEvent QKeyEvent 1451 QFocusEvent QPaintEvent QMoveEvent QResizeEvent QCloseEvent 1452 QShowEvent QHideEvent QContextMenuEvent QIMEvent QDropEvent 1453 QDragMoveEvent QDragEnterEvent QDragResponseEvent QDragLeaveEvent 1454 QChildEvent QCustomEvent) 1455 (qdatetime.h QTime QDateTime QDate) 1456 1457 ; Qt/Embedded 1458 (qcopchannel_qws.h QCopChannel) 1459 (qdirectpainter_qws.h QDirectPainter) 1460 (qfontfactorybdf_qws.h QFontFactoryBDF) 1461 (qfontfactoryttf_qws.h QFontFactoryFT) 1462 (qfontmanager_qws.h QGlyphMetrics QGlyph QRenderedFont QDiskFont QFontManager QFontFactory) 1463 (qgfx_qws.h QScreenCursor QPoolEntry QScreen QGfx) 1464 (qgfxlinuxfb_qws.h QLinuxFbScreen) 1465 (qgfxmatroxdefs_qws.h QQnxFbGfx QQnxScreen) 1466 (qgfxraster_qws.h QGfxRasterBase QGfxRaster) 1467 (qgfxvnc_qws.h QRfbRect QRfbPixelFormat QRfbServerInit QRfbSetEncodings 1468 QRfbFrameBufferUpdateRequest QRfbKeyEvent QRfbPointerEvent QRfbClientCutText QVNCServer) 1469 (qkeyboard_qws.h QWSKeyboardHandler) 1470 (qlock_qws.h QLock QLockHolder) 1471 (qmemorymanager_qws.h QMemoryManagerPixmap QMemoryManager) 1472 (qsoundqss_qws.h QWSSoundServer QWSSoundClient QWSSoundServerClient QWSSoundServerSocket) 1473 (qwindowsystem_qws.h QWSInternalWindowInfo QWSScreenSaver QWSWindow QWSSoundServer 1474 QWSServer QWSServer KeyboardFilter QWSClient) 1475 (qwsbeosdecoration_qws.h QWSBeOSDecoration) 1476 (qwscursor_qws.h QWSCursor) 1477 (qwsdecoration_qws.h QWSDecoration) 1478 (qwsdefaultdecoration_qws.h QWSDefaultDecoration) 1479 (qwsdisplay_qws.h QWSWindowInfo QWSDisplay) 1480 (qwshydrodecoration_qws.h QWSHydroDecoration) 1481 (qwskde2decoration_qws.h QWSKDE2Decoration) 1482 (qwskdedecoration_qws.h QWSKDEDecoration) 1483 (qwsmanager_qws.h QWSManager QWSButton) 1484 (qwsmouse_qws.h QWSPointerCalibrationData QWSMouseHandler QCalibratedMouseHandler 1485 QAutoMouseHandlerPrivate QWSMouseHandlerPrivate QVrTPanelHandlerPrivate 1486 QTPanelHandlerPrivate QYopyTPanelHandlerPrivate QCustomTPanelHandlerPrivate 1487 QVFbMouseHandlerPrivate) 1488 (qwsproperty_qws.h QWSPropertyManager) 1489 (qwsregionmanager_qws.h QWSRegionManager) 1490 (qwssocket_qws.h QWSSocket QWSServerSocket) 1491 (qwswindowsdecoration_qws.h QWSWindowsDecoration) 1492 1493 ; KDE 1494 (kdebug.h kDebug kWarning kError kFatal kBacktrace) 1495 1496 ) "List of special include files which do not follow the normal scheme") 1497 1498 ;; Lookup class `cls' in kdab-special-includes and return the associate include file name 1499 (defun kdab-map-special (cls) 1500 (let ((list kdab-special-includes) 1501 (found nil)) 1502 (while (and list (not found)) 1503 (let* ( (elm (car list)) 1504 (include-file (car elm)) 1505 (classes (cdr elm))) 1506 ( while (and classes (not found)) 1507 (if (string= (downcase cls) (downcase (symbol-name (car classes)))) 1508 (setq found include-file) 1509 (setq classes (cdr classes))))) 1510 (setq list (cdr list))) 1511 (if found 1512 (symbol-name found) 1513 nil) ; return value 1514 )) 1515 1516 1517 (defun kdab-word-under-point () 1518 (save-excursion 1519 (let* ((start (if (= (preceding-char) ?\ ) 1520 (point) 1521 (progn (backward-word 1) (point)))) 1522 (end (progn (forward-word 1) (point)))) 1523 (buffer-substring start end)))) 1524 1525 1526 ;-------------------------------------------------------------------------------- 1527 ; Insert include file. 1528 ; Place point anywhere on a class, and invoke this function. A result of 1529 ; this is that an include line is added (if it does not already exists) for 1530 ; the given class. 1531 ;-------------------------------------------------------------------------------- 1532 (defun kdab-insert-header () 1533 (interactive "") 1534 (save-excursion 1535 (let* ((word (downcase (kdab-word-under-point))) 1536 (header (cond 1537 ((kdab-map-special word) (kdab-map-special word)) 1538 ((string-match "^qdom" word) "qdom.h") 1539 ((string-match "^qxml" word) "qxml.h") 1540 (t (concat word ".h"))))) 1541 (beginning-of-buffer) 1542 (if (not (re-search-forward (concat "#include *<" header ">") nil t)) 1543 (progn 1544 ; No include existsed 1545 (goto-char (point-max)) ; Using end-of-buffer makes point move, dispete save-excursion 1546 (if (not (re-search-backward "^#include *[\"<][^\">]+\.h *[\">]" nil t)) 1547 (beginning-of-buffer) 1548 (progn (end-of-line) (forward-char 1))) 1549 (if (file-exists-p header) 1550 (progn 1551 ; See this as a local file. 1552 (insert "#include \"" header "\"\n") 1553 (message (concat "inserted " "#include \"" header "\""))) 1554 (progn 1555 (insert "#include <" header ">\n") 1556 (message (concat "inserted " "#include <" header ">"))))) 1557 (message (concat "header file \"" header "\" is already included")))))) 1558 1559 1560 1561 1562 ;-------------------------------------------------------------------------------- 1563 ; Start konqueror with documentation for the class under point. 1564 ; set `kdab-qt-documentation' to specify the replacement for the documentation 1565 ;-------------------------------------------------------------------------------- 1566 (defun kdab-lookup-qt-documentation () 1567 (interactive "") 1568 (save-excursion 1569 (let* ((word (downcase (kdab-word-under-point))) 1570 (url (if (not (string-match "XXX" kdab-qt-documentation)) 1571 (error "didn't find three X's in kdab-qt-documentation") 1572 (replace-match word t t kdab-qt-documentation)))) 1573 (start-process "qt documentation" nil "kfmclient" "openURL" url) 1574 (message (concat "Loading " url))))) 1575 1576 1577 ;; ----- Third part, contributed by various KDE developers 1578 1579 ;;; func-menu is a package that scans your source file for function definitions 1580 ;;; and makes a menubar entry that lets you jump to any particular function 1581 ;;; definition by selecting it from the menu. The following code turns this on 1582 ;;; for all of the recognized languages. Scanning the buffer takes some time, 1583 ;;; but not much. 1584 1585 (if xemacs 1586 (progn 1587 (require 'func-menu) 1588 (add-hook 'find-file-hooks 'fume-add-menubar-entry) ) 1589 (progn 1590 (require 'imenu))) 1591 ;(add-hook 'find-file-hooks 'imenu)) ) 1592 1593 ;; Switch between the declaration of a class member in .cc/.cpp/.C, and its definition in the .h file 1594 ;; Written by David and Reggie after much hair tearing 1595 (defun switch-to-function-def () 1596 (interactive) 1597 (let ((n (buffer-file-name)) 1598 (class "") 1599 (fn "")) 1600 (if (or (string-match "\\.cc$" n) 1601 (string-match "\\.cpp$" n) 1602 (string-match "\\.C$" n)) 1603 (let ((a (fume-function-before-point))) 1604 (and (string-match "^\\(.*\\)::\\(.*\\)$" a) 1605 (progn 1606 (setq class (match-string 1 a)) 1607 (setq fn (match-string 2 a)) 1608 (agulbra-switch-cpp-h) 1609 (goto-char 0) 1610 (re-search-forward class nil t) 1611 (re-search-forward (concat "[ \t]+" fn "[ \t]*(") nil t))))) 1612 (if (string-match "\\.h$" n) 1613 (progn 1614 (save-excursion 1615 (forward-line 0) 1616 (re-search-forward "[ \t]+\\([^ \t(]+\\)[ \t]*(" nil t) 1617 (setq fn (match-string 1)) 1618 (re-search-backward "^class \\([a-zA-Z0-9_]+\\)[ \t]*\\([a-zA-Z0-9_]*\\)" nil t) 1619 (setq class (match-string 1)) 1620 (setq save (match-string 2)) 1621 (and (string-match "Q_EXPORT" class) 1622 (setq class save)) 1623 (message (concat class "::" fn)) 1624 ) 1625 (agulbra-switch-cpp-h) 1626 (goto-char 0) 1627 (re-search-forward (concat "^[^()]*" class "::" fn "[ \t]*(") nil t) 1628 (message c-syntactic-context) 1629 ) 1630 ))) 1631 1632 ; Adds the current file to Makefile.am. 1633 ; Written by David. 1634 (defun add-file-to-makefile-am () 1635 "add the current file to the _SOURCES tag in the Makefile.am" 1636 (interactive) 1637 (let ((file (buffer-name)) 1638 (makefile "Makefile.am")) 1639 (if (file-readable-p makefile ) 1640 (message "") 1641 (error "Makefile.am not found!") 1642 ) 1643 (find-file makefile) 1644 (goto-char (point-min)) 1645 (if (re-search-forward "_SOURCES" nil t) 1646 (progn 1647 (end-of-line) 1648 ; check if line ends with '\' [had to read make-mode.el to find this one!] 1649 (while (= (char-before) ?\\) 1650 (end-of-line 2)) ; moves to end of next line 1651 (insert " ") 1652 (insert file) 1653 ) 1654 (error "_SOURCES not found") 1655 ) 1656 ) 1657 ) 1658 1659 ; Inserts a kDebug statement showing the name of the current method. 1660 ; You need to create the empty line first. 1661 (defun insert-kDebug () 1662 (interactive) 1663 (insert "kDebug() << \"") 1664 (insert (fume-function-before-point)) 1665 (insert "\" << endl;") 1666 ) 1667 1668 ; Creates the ifndef/define/endif statements necessary for a header file 1669 (defun header-protection () 1670 (interactive) 1671 (let ((f (buffer-file-name))) 1672 (if (string-match "^.*/" f) 1673 (setq f (replace-match "" t t f))) 1674 (while (string-match "\\." f) 1675 (setq f (replace-match "_" t t f))) 1676 (save-excursion 1677 (goto-char (point-min)) 1678 (insert "#ifndef " (upcase f) "\n#define " (upcase f) "\n\n") 1679 (goto-char (point-max)) 1680 (insert "\n#endif\n") 1681 ) 1682 ) 1683 ) 1684 1685 1686 ; Makes '(' insert '(' or ' ( ' where appropiate 1687 (defun insert-parens (arg) (interactive "*P") 1688 (if (not (c-in-literal)) 1689 (let ((n nil)) 1690 (save-excursion 1691 (setq n (or (progn (forward-char -2) (looking-at "if")) 1692 (progn (forward-char -1) (looking-at "for")) 1693 (progn (forward-char -1) (looking-at "case")) 1694 (progn (forward-char -1) (looking-at "while")) 1695 ) 1696 ) 1697 ) 1698 (cond 1699 (n (progn 1700 (insert " ") 1701 (self-insert-command (prefix-numeric-value arg)) 1702 ;(insert " ") 1703 )) 1704 (t ;else 1705 (self-insert-command (prefix-numeric-value arg)) 1706 ;(insert " ") 1707 ))) 1708 (self-insert-command (prefix-numeric-value arg))) 1709 ) 1710 1711 (defun insert-parens2 (arg) (interactive "*P") 1712 (if (not (c-in-literal)) 1713 (let ((remv nil) (nospac nil)) 1714 (forward-char -2) 1715 (setq remv (looking-at "( ")) ; () -> we'll have to remove that space 1716 (forward-char 1) 1717 (setq nospac (or (looking-at " ") (looking-at "(")) ) ; no space to be added 1718 (forward-char 1) 1719 (cond 1720 (remv (progn 1721 (delete-backward-char 1) 1722 (self-insert-command (prefix-numeric-value arg)))) ; the () case 1723 (nospac (self-insert-command (prefix-numeric-value arg))) ; no space to be added 1724 (t ;else 1725 (if abbrev-mode ; XEmacs 1726 (expand-abbrev)) 1727 ;(insert " ") 1728 (self-insert-command (prefix-numeric-value arg)) 1729 ))) ; normal case, prepend a space 1730 ;;(blink-matching-open) ; show the matching parens 1731 (self-insert-command (prefix-numeric-value arg))) 1732 ) 1733 1734 ; Makes ',' insert ', ' 1735 (defun insert-comma (arg) 1736 (interactive "*P") 1737 (let* ((ch (char-after)) 1738 (spacep (not (or (eq ch ? ) 1739 (c-in-literal) 1740 arg)))) 1741 (self-insert-command (prefix-numeric-value arg)) 1742 (if spacep 1743 (insert " ")))) 1744 1745 (defun insert-curly-brace (arg) (interactive "*P") 1746 (if (not (c-in-literal)) 1747 (let ((n nil) (o nil)) 1748 (save-excursion 1749 (forward-char -2) 1750 (setq o (looking-at "()")) 1751 (forward-char 1) 1752 (setq n (looking-at ")")) 1753 ) 1754 (cond 1755 (n (progn 1756 (insert " ") 1757 (self-insert-command (prefix-numeric-value arg)) 1758 (newline-and-indent) 1759 (save-excursion 1760 (insert "\n}") 1761 (c-indent-line) 1762 ))) 1763 (o (progn 1764 (newline) 1765 (self-insert-command (prefix-numeric-value arg)) 1766 (newline-and-indent))) 1767 (t (progn ;else 1768 (self-insert-command (prefix-numeric-value arg)) 1769 (save-excursion 1770 (beginning-of-line) 1771 (c-indent-command)))) 1772 )) 1773 (self-insert-command (prefix-numeric-value arg)) 1774 ) 1775 ) 1776 1777 ;; have PelDel mode work 1778 (put 'insert-parens 'pending-delete t) 1779 (put 'insert-parens2 'pending-delete t) 1780 (put 'insert-comma 'pending-delete t) 1781 (put 'insert-curly-brace 'pending-delete t) 1782 (put 'newline-and-indent 'pending-delete t) 1783 1784 ; A wheel mouse that doesn't beep, unlike mwheel-install 1785 (defun scroll-me-up () (interactive) (scroll-up 4)) 1786 (defun scroll-me-down () (interactive) (scroll-down 4)) 1787 (defun scroll-me-up-a-bit () (interactive) (scroll-up 1)) 1788 (defun scroll-me-down-a-bit () (interactive) (scroll-down 1)) 1789 (define-key global-map [(button4)] 'scroll-me-down) 1790 (define-key global-map [(button5)] 'scroll-me-up) 1791 (define-key global-map [(shift button4)] 'scroll-me-down-a-bit) 1792 (define-key global-map [(shift button5)] 'scroll-me-up-a-bit) 1793 1794 ; Compilation 1795 (defun makeclean () (interactive) (compile "make clean")) 1796 (defun make () (interactive) (compile "make")) 1797 (defun makeinstall () (interactive) (compile "make install")) 1798 (defun makeinstallexec () (interactive) (compile "make install-exec")) 1799 (defun makethisfile () (interactive) 1800 (let ((f (buffer-name))) 1801 (if (string-match "\.cpp$" f) (setq f (replace-match "\.lo" t t f))) 1802 (if (string-match "\.cc$" f) (setq f (replace-match "\.lo" t t f))) 1803 (compile (concat "make " f )))) 1804 1805 ;; Indentation: 4 characters, no tabs. 1806 (setq c-basic-offset 4) 1807 (setq insert-tab-mode nil) 1808 (setq-default require-final-newline t) 1809 (setq-default next-line-add-newlines nil) 1810 1811 ;; pc-like textmarking 1812 (load "pc-select") 1813 (if xemacs 1814 (pc-select-mode) 1815 (pc-selection-mode)) 1816 1817 ; Move in other window 1818 (defun scroll-other-up () (interactive) (scroll-other-window-down 1)) ; hehe :) 1819 (define-key global-map [(meta up)] 'scroll-other-up) 1820 (defun scroll-other-down () (interactive) (scroll-other-window 1)) 1821 (define-key global-map [(meta down)] 'scroll-other-down) 1822 1823 ;; Some example bindings, feel free to customize :) 1824 (define-key global-map [(f2)] 'grep) 1825 ;; FIXME: remember to get these two working on Gnu/Emacs (Zack) 1826 (define-key global-map [(f3)] 'fume-list-functions) 1827 (define-key global-map [(shift f3)] 'fume-prompt-function-goto) 1828 (define-key global-map [(shift button3)] 'mouse-function-menu) 1829 (define-key global-map [(shift f4)] 'makeclean) 1830 (define-key global-map [(f4)] 'make) 1831 (define-key global-map [(f5)] 'makeinstall) 1832 (define-key global-map [(shift f5)] 'makeinstallexec) 1833 (define-key global-map [(shift f6)] 'makethisfile) 1834 (define-key global-map [(f6)] 'agulbra-switch-cpp-h) 1835 (define-key global-map [(f7)] 'switch-to-function-def) 1836 ;; imenu does that interactively 1837 (if xemacs 1838 (define-key global-map [(f8)] 'function-menu)) 1839 ;(define-key global-map [(f9)] 'agulbra-make-member) ;; uncomment this for a killer feature 1840 (define-key global-map [(f10)] 'kdab-insert-header) 1841 (define-key global-map [(shift f10)] 'kdab-lookup-qt-documentation) 1842 (define-key global-map [(control meta d)] 'insert-kDebug) 1843 1844 ; Standard Qt/KDE shortcuts: Ctrl+Backspace, Ctrl+Delete 1845 (define-key global-map [(control backspace)] 'backward-kill-word) 1846 (define-key global-map [(control delete)] 'kill-word) 1847 1848 ; Standard Qt/KDE shortcuts: Control Pageup and Pagedown 1849 (define-key global-map [(control prior)] 'beginning-of-buffer) 1850 (define-key global-map [(control next)] 'end-of-buffer) 1851 1852 ; currently no binding for header-protection and add-file-to-makefile-am, 1853 ; you need to call them from M-x 1854 1855 ; ----------------------------------------------------------------- 1856 ; The above list defines the following bindings: 1857 ; 1858 ; F2 : offer a grep command 1859 ; 1860 ; F3/Shift-F3/F8/Shift-RMB : different ways to see the list of methods in the current buffer 1861 ; 1862 ; F4 : make 1863 ; Shift-F4 : make clean 1864 ; F5 : make install 1865 ; Shift-F5 : make install-exec 1866 ; 1867 ; Shift-F6 : compile this file [assumes libtool is being used] 1868 ; F6 : Switch from .cpp/.cc to .h and vice-versa 1869 ; F7 : The same, but try to find the current method in the other file 1870 ; F9 (if enabled) : Create a member method in the .cpp, the cursor being on the definition in the .h 1871 ; F10: Place point on a class name, and the respective (Qt) include file will be inserted. 1872 ; This works with all Qt classes but can easily be extended to KDE classes. 1873 ; Shift-F10: Place point on a class name, and press Shift-F10, and konqueror will load 1874 ; Qt documentation. Customize the location of the Qt documentation with the 1875 ; variable kdab-qt-documentation. XXX will be replace with the class name. 1876 ; Example (setq kdab-qt-location "file:/packages/kde-src/qt-copy/doc/html/XXX.html") 1877 ; 1878 ; Ctrl+Meta+D : insert a kDebug statement with the name of the current method 1879 ; [the new hide-all-windows shortcut conflicts with that, you may have to 1880 ; change it, or use Ctrl+Meta+Shift+D (!!)] 1881 ; 1882 ; Meta Up/Down : scroll the other window (when window is split) 1883 1884 ; Other very useful keybindings to know about: 1885 ; C-x r m to set a named bookmark in the buffer 1886 ; C-x r b to jump to a named bookmark in the buffer 1887 1888 (setq-default initial-scratch-message 1889 "File kde-devel-emacs.el is deprecated! 1890 Please use KDE-Emacs from kdesdk/scripts/kde-emacs.")