1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
|
;; kde-emacs-core.el - core functionality,e.g. syntax & c++-mode-hook
;;
;; Copyright (C) 2002 KDE Development Team <www.kde.org>
;;
;; This library is free software; you can redistribute it and/or
;; modify it under the terms of the GNU Lesser General Public
;; License as published by the Free Software Foundation; either
;; version 2.1 of the License, or (at your option) any later version.
;;
;; This library is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; Lesser General Public License for more details.
;;
;; You should have received a copy of the GNU Lesser General Public
;; License along with this library; if not, write to the Free Software
;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
;; 02110-1301 USA
(require 'kde-emacs-vars)
;*---------------------------------------------------------------------*/
;* Variables ... */
;*---------------------------------------------------------------------*/
(defcustom kde-tab-behavior 'default
"Specifies the current tab behavior. default will expand try to complete
the symbol at point if at the end of something that looks like an indentifier else
it will indent the current line if the pointer is at the beginning of the line it will
be moved to the start of the indention. abbrev-indent behaves like default, but the
cursor isn't moved to the beginning of the indention with tab is pressed when the cursor
is at the beginning of the line. indent simply indents the line without trying to
complete the symbol"
:group 'kde-devel
:version "0.1"
:type `(choice (const default) (const abbrev-indent) (const indent)))
;*---------------------------------------------------------------------*/
;* Functions ... */
;*---------------------------------------------------------------------*/
;; ------- First part, from Arnt's "c++ stuff" - slightly modified for our needs :)
(defun agulbra-c++-tab (arg)
"Do the right thing about tabs in c++ mode.
Try to finish the symbol, or indent the line."
(interactive "*P")
(cond
((and (not (looking-at "[A-Za-z0-9]"))
(save-excursion
(forward-char -1)
(looking-at "[A-Za-z0-9:>_\\-\\&\\.(){}\\*\\+/]")))
(dabbrev-expand arg))
(t
(if (eq kde-tab-behavior 'default)
(c-indent-command)
(save-excursion
(beginning-of-line)
(c-indent-command))))))
(defun agulbra-clean-out-spaces ()
"Remove spaces at ends of lines."
(interactive)
(and (not buffer-read-only)
(save-excursion
(goto-char (point-min))
(let ((count 0)
(bmp (buffer-modified-p)))
(while (re-search-forward "[ \t]+$" nil t)
(setq count (1+ count))
(replace-match "" t t))
(set-buffer-modified-p bmp)
nil
))))
; the above used to contain (untabify (point-min) (point-max)) too
(defun agulbra-c++-clean-out-spaces ()
"Remove spaces at ends of lines, only in c++ mode."
(interactive)
(if (eq major-mode 'c++-mode)
(agulbra-clean-out-spaces)
)
)
(defun agulbra-delete-into-nomenclature (&optional arg)
"Delete forward until the end of a nomenclature section or word.
With arg, do it arg times."
(interactive "p")
(save-excursion
(let ((b (point-marker)))
(c-forward-into-nomenclature arg)
(delete-region b (point-marker)))))
(if (not (fboundp 'font-lock-add-keywords))
(defun font-lock-add-keywords (mode keywords &optional append)
"XEmacs doesn't have font-lock-add-keywords so we provide it."
(font-lock-set-defaults)
(if (eq append 'set)
(setq font-lock-keywords keywords)
; NOTE: write this function for XEmacs - Zack
;(font-lock-remove-keywords nil keywords) ;to avoid duplicates
(let ((old (if (eq (car-safe font-lock-keywords) t)
(cdr font-lock-keywords)
font-lock-keywords)))
(setq font-lock-keywords (if append
(append old keywords)
(append keywords old))))))
)
(c-add-style "kde-c" '("stroustrup"
(c-basic-offset . 4)
(c-offsets-alist
(case-label . 4)
(access-label . -)
(label . 0)
(statement-cont . c-lineup-math)
)))
; ( we use Backquote ( '`' ) instead of "'" because we want
; kde-access-labels to be evaluated... )
(c-add-style "kde-c++" `("kde-c"
;;FIXME: 1) fume functions not available on GNU/Emacs
;; 2) insert-tab-mode no longer present (free variable)
;; 3) c-hangin-commment-under-p no longer present (free variable)
(if (not (eq kde-tab-behavior 'indent))
(c-tab-always-indent . nil))
; (insert-tab-mode nil)
(indent-tabs-mode . nil)
(if (eq kde-emacs-type 'xemacs)
(fume-auto-rescan-buffer-p nil))
(c-access-key . ,kde-access-labels)
(c-opt-access-key . ,kde-access-labels)
; (c-hanging-comment-under-p nil)
(c-offsets-alist . ((case-label . 0)
(inline-open . 0)))
))
;; KDE C++ mode
;; Not a "(setq c++-mode-hook ..." because this way we would
;; prune all other hooks!
(defun kde-c++-mode-hook ()
(font-lock-mode)
(c-set-style kde-c++-style)
(define-key c++-mode-map "\C-m" 'c-context-line-break)
(when (or
(eq kde-tab-behavior 'default)
(eq kde-tab-behavior 'abbrev-indent))
(define-key c++-mode-map "\C-i" 'agulbra-c++-tab))
(define-key c++-mode-map "\ef" 'c-forward-into-nomenclature)
(define-key c++-mode-map "\ed" 'agulbra-delete-into-nomenclature)
(define-key c++-mode-map "\eb" 'c-backward-into-nomenclature)
;; fontify "public|protected|private slots" with one and the same face :)
;; NOTE: write face-at-point function to fontify those just like other
;; access specifiers
;; This breaks in the font-lock-fontify engine in xemacs-21.5.28... no solution known yet.
;; TODO use the const variable kde-access-labels here. Couldn't figure out the syntax.
;(font-lock-add-keywords nil '(("\\<\\(signals\\|Q_SIGNALS\\|k_dcop\\|\\(public\\|protected\\|private\\)\\([ ]+\\(slots\\|Q_SLOTS\\)\\)?\\)\\>:" . font-lock-reference-face)))
;; Add (setq magic-keys-mode nil) to your .emacs (before loading this file)
;; to disable the magic keys in C++ mode.
(and (boundp 'magic-keys-mode) magic-keys-mode
(progn
(define-key c++-mode-map "\," 'insert-comma)
(define-key c++-mode-map "\{" 'insert-curly-brace)
(define-key c++-mode-map "\(" 'insert-parens)
(define-key c++-mode-map "\)" 'insert-parens2)
))
)
(defun kde-c-mode-hook ()
(font-lock-mode)
(c-set-style kde-c-style))
(and (user-variable-p 'kde-emacs-delete-trailing-whitespace)
kde-emacs-delete-trailing-whitespace
(progn
(add-hook 'find-file-hooks 'agulbra-c++-clean-out-spaces)
(add-hook 'write-file-hooks 'agulbra-c++-clean-out-spaces)
))
(add-hook 'c++-mode-hook 'kde-c++-mode-hook)
(add-hook 'c-mode-hook 'kde-c-mode-hook)
; always end a file with a newline
(setq-default require-final-newline t)
; 'next-line won't be adding newlines
(setq-default next-line-add-newlines nil)
(setq compilation-error-regexp-systems-list '(gnu of comma 4bsd)
compilation-ask-about-save nil)
(provide 'kde-emacs-core)
|