Warning, /sdk/kde-dev-scripts/kde-emacs/kde-emacs-core.el is written in an unsupported language. File is not indexed.
0001 ;; kde-emacs-core.el - core functionality,e.g. syntax & c++-mode-hook
0002 ;;
0003 ;; Copyright (C) 2002 KDE Development Team <www.kde.org>
0004 ;;
0005 ;; This library is free software; you can redistribute it and/or
0006 ;; modify it under the terms of the GNU Lesser General Public
0007 ;; License as published by the Free Software Foundation; either
0008 ;; version 2.1 of the License, or (at your option) any later version.
0009 ;;
0010 ;; This library is distributed in the hope that it will be useful,
0011 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
0012 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0013 ;; Lesser General Public License for more details.
0014 ;;
0015 ;; You should have received a copy of the GNU Lesser General Public
0016 ;; License along with this library; if not, write to the Free Software
0017 ;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
0018 ;; 02110-1301 USA
0019
0020 (require 'kde-emacs-vars)
0021 ;*---------------------------------------------------------------------*/
0022 ;* Variables ... */
0023 ;*---------------------------------------------------------------------*/
0024
0025 (defcustom kde-tab-behavior 'default
0026 "Specifies the current tab behavior. default will expand try to complete
0027 the symbol at point if at the end of something that looks like an indentifier else
0028 it will indent the current line if the pointer is at the beginning of the line it will
0029 be moved to the start of the indention. abbrev-indent behaves like default, but the
0030 cursor isn't moved to the beginning of the indention with tab is pressed when the cursor
0031 is at the beginning of the line. indent simply indents the line without trying to
0032 complete the symbol"
0033 :group 'kde-devel
0034 :version "0.1"
0035 :type `(choice (const default) (const abbrev-indent) (const indent)))
0036
0037 ;*---------------------------------------------------------------------*/
0038 ;* Functions ... */
0039 ;*---------------------------------------------------------------------*/
0040
0041
0042 ;; ------- First part, from Arnt's "c++ stuff" - slightly modified for our needs :)
0043
0044 (defun agulbra-c++-tab (arg)
0045 "Do the right thing about tabs in c++ mode.
0046 Try to finish the symbol, or indent the line."
0047 (interactive "*P")
0048 (cond
0049 ((and (not (looking-at "[A-Za-z0-9]"))
0050 (save-excursion
0051 (forward-char -1)
0052 (looking-at "[A-Za-z0-9:>_\\-\\&\\.(){}\\*\\+/]")))
0053 (dabbrev-expand arg))
0054 (t
0055 (if (eq kde-tab-behavior 'default)
0056 (c-indent-command)
0057 (save-excursion
0058 (beginning-of-line)
0059 (c-indent-command))))))
0060
0061 (defun agulbra-clean-out-spaces ()
0062 "Remove spaces at ends of lines."
0063 (interactive)
0064 (and (not buffer-read-only)
0065 (save-excursion
0066 (goto-char (point-min))
0067 (let ((count 0)
0068 (bmp (buffer-modified-p)))
0069 (while (re-search-forward "[ \t]+$" nil t)
0070 (setq count (1+ count))
0071 (replace-match "" t t))
0072 (set-buffer-modified-p bmp)
0073 nil
0074 ))))
0075
0076 ; the above used to contain (untabify (point-min) (point-max)) too
0077
0078 (defun agulbra-c++-clean-out-spaces ()
0079 "Remove spaces at ends of lines, only in c++ mode."
0080 (interactive)
0081 (if (eq major-mode 'c++-mode)
0082 (agulbra-clean-out-spaces)
0083 )
0084 )
0085
0086 (defun agulbra-delete-into-nomenclature (&optional arg)
0087 "Delete forward until the end of a nomenclature section or word.
0088 With arg, do it arg times."
0089 (interactive "p")
0090 (save-excursion
0091 (let ((b (point-marker)))
0092 (c-forward-into-nomenclature arg)
0093 (delete-region b (point-marker)))))
0094
0095
0096 (if (not (fboundp 'font-lock-add-keywords))
0097 (defun font-lock-add-keywords (mode keywords &optional append)
0098 "XEmacs doesn't have font-lock-add-keywords so we provide it."
0099 (font-lock-set-defaults)
0100 (if (eq append 'set)
0101 (setq font-lock-keywords keywords)
0102 ; NOTE: write this function for XEmacs - Zack
0103 ;(font-lock-remove-keywords nil keywords) ;to avoid duplicates
0104 (let ((old (if (eq (car-safe font-lock-keywords) t)
0105 (cdr font-lock-keywords)
0106 font-lock-keywords)))
0107 (setq font-lock-keywords (if append
0108 (append old keywords)
0109 (append keywords old))))))
0110 )
0111
0112 (c-add-style "kde-c" '("stroustrup"
0113 (c-basic-offset . 4)
0114 (c-offsets-alist
0115 (case-label . 4)
0116 (access-label . -)
0117 (label . 0)
0118 (statement-cont . c-lineup-math)
0119 )))
0120
0121 ; ( we use Backquote ( '`' ) instead of "'" because we want
0122 ; kde-access-labels to be evaluated... )
0123 (c-add-style "kde-c++" `("kde-c"
0124 ;;FIXME: 1) fume functions not available on GNU/Emacs
0125 ;; 2) insert-tab-mode no longer present (free variable)
0126 ;; 3) c-hangin-commment-under-p no longer present (free variable)
0127 (if (not (eq kde-tab-behavior 'indent))
0128 (c-tab-always-indent . nil))
0129 ; (insert-tab-mode nil)
0130 (indent-tabs-mode . nil)
0131 (if (eq kde-emacs-type 'xemacs)
0132 (fume-auto-rescan-buffer-p nil))
0133 (c-access-key . ,kde-access-labels)
0134 (c-opt-access-key . ,kde-access-labels)
0135 ; (c-hanging-comment-under-p nil)
0136 (c-offsets-alist . ((case-label . 0)
0137 (inline-open . 0)))
0138 ))
0139
0140 ;; KDE C++ mode
0141 ;; Not a "(setq c++-mode-hook ..." because this way we would
0142 ;; prune all other hooks!
0143 (defun kde-c++-mode-hook ()
0144 (font-lock-mode)
0145 (c-set-style kde-c++-style)
0146 (define-key c++-mode-map "\C-m" 'c-context-line-break)
0147 (when (or
0148 (eq kde-tab-behavior 'default)
0149 (eq kde-tab-behavior 'abbrev-indent))
0150 (define-key c++-mode-map "\C-i" 'agulbra-c++-tab))
0151 (define-key c++-mode-map "\ef" 'c-forward-into-nomenclature)
0152 (define-key c++-mode-map "\ed" 'agulbra-delete-into-nomenclature)
0153 (define-key c++-mode-map "\eb" 'c-backward-into-nomenclature)
0154 ;; fontify "public|protected|private slots" with one and the same face :)
0155 ;; NOTE: write face-at-point function to fontify those just like other
0156 ;; access specifiers
0157 ;; This breaks in the font-lock-fontify engine in xemacs-21.5.28... no solution known yet.
0158 ;; TODO use the const variable kde-access-labels here. Couldn't figure out the syntax.
0159 ;(font-lock-add-keywords nil '(("\\<\\(signals\\|Q_SIGNALS\\|k_dcop\\|\\(public\\|protected\\|private\\)\\([ ]+\\(slots\\|Q_SLOTS\\)\\)?\\)\\>:" . font-lock-reference-face)))
0160
0161 ;; Add (setq magic-keys-mode nil) to your .emacs (before loading this file)
0162 ;; to disable the magic keys in C++ mode.
0163 (and (boundp 'magic-keys-mode) magic-keys-mode
0164 (progn
0165 (define-key c++-mode-map "\," 'insert-comma)
0166 (define-key c++-mode-map "\{" 'insert-curly-brace)
0167 (define-key c++-mode-map "\(" 'insert-parens)
0168 (define-key c++-mode-map "\)" 'insert-parens2)
0169 ))
0170 )
0171
0172 (defun kde-c-mode-hook ()
0173 (font-lock-mode)
0174 (c-set-style kde-c-style))
0175
0176 (and (user-variable-p 'kde-emacs-delete-trailing-whitespace)
0177 kde-emacs-delete-trailing-whitespace
0178 (progn
0179 (add-hook 'find-file-hooks 'agulbra-c++-clean-out-spaces)
0180 (add-hook 'write-file-hooks 'agulbra-c++-clean-out-spaces)
0181 ))
0182
0183 (add-hook 'c++-mode-hook 'kde-c++-mode-hook)
0184 (add-hook 'c-mode-hook 'kde-c-mode-hook)
0185 ; always end a file with a newline
0186 (setq-default require-final-newline t)
0187 ; 'next-line won't be adding newlines
0188 (setq-default next-line-add-newlines nil)
0189 (setq compilation-error-regexp-systems-list '(gnu of comma 4bsd)
0190 compilation-ask-about-save nil)
0191
0192 (provide 'kde-emacs-core)