Warning, /sdk/kde-dev-scripts/kde-emacs/kde-emacs-general.el is written in an unsupported language. File is not indexed.
0001 ;; kde-emacs-general.el 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 ;;; Commentary: 0021 ;; 0022 0023 ;;; Code: 0024 0025 (require 'kde-emacs-vars) 0026 (require 'sourcepair) 0027 0028 ;*---------------------------------------------------------------------*/ 0029 ;* Functions ... */ 0030 ;*---------------------------------------------------------------------*/ 0031 0032 ;; remassoc exists as a built-in function in xemacs, but 0033 ;; not in GNU emacs 0034 (if (not (functionp 'remassoc)) 0035 (defun remassoc (key a) 0036 "remove an association pair from an alist" 0037 (if a 0038 (let ((pair (car a))) 0039 (if (equal (car pair) key) 0040 (cdr a) 0041 (cons pair (remassoc key (cdr a)))))))) 0042 0043 ;; Helper for kde-file-get-cpp-h 0044 (defun kde-find-file (filename basedir) 0045 "Looks for \"filename\" under \"basedir\"" 0046 (if basedir 0047 (let ((path (concat basedir "/" filename))) 0048 (if (file-readable-p path) 0049 path)) 0050 ) 0051 ) 0052 0053 ;; Helper for kde-file-get-cpp-h 0054 (defun kde-file-or-buffer-exists (path) 0055 "Returns true if \"filename\" is an existing file, or an open buffer" 0056 (or (file-readable-p path) 0057 (get-file-buffer path)) 0058 ) 0059 0060 (setq kde-file-lookup-cache '()) 0061 0062 (defun kde-update-file-lookup-cache (file1 file2) 0063 (setq kde-file-lookup-cache (remassoc file1 kde-file-lookup-cache)) 0064 (setq kde-file-lookup-cache (remassoc file2 kde-file-lookup-cache)) 0065 (setq kde-file-lookup-cache 0066 (cons (cons file1 file2) 0067 (cons (cons file2 file1) kde-file-lookup-cache)))) 0068 0069 (defun kde-file-get-cpp-h () 0070 "Function returns a corresponding source or header file. The returned 0071 variable is a list of the form (FILENAME IS_READABLE) e.g. when being in 0072 test.h file and having test.cpp file readable in the same directory it will 0073 return (\"test.cpp\" t)." 0074 0075 (save-excursion 0076 (let* ((current-file (buffer-file-name)) 0077 (match (assoc current-file kde-file-lookup-cache)) 0078 associated-file 0079 buffer) 0080 (if match 0081 (progn 0082 (kde-update-file-lookup-cache current-file (cdr match)) 0083 (cons (cdr match) 't)) ; return value 0084 0085 (progn ;; else !match 0086 (setq buffer (sourcepair-load)) 0087 (if (stringp buffer) 0088 (cons "" nil) ; return value 0089 (progn ;; Found a value 0090 (setq associated-file (buffer-file-name buffer)) 0091 (kde-update-file-lookup-cache current-file associated-file) 0092 (cons (buffer-file-name buffer) 't)))))))) 0093 0094 (defun kde-switch-cpp-h () 0095 "Switches between the source and the header file (both directions)." 0096 (interactive) 0097 (let ((file (kde-file-get-cpp-h)) 0098 (base-name-no-ext (file-name-nondirectory (file-name-sans-extension (buffer-file-name))))) 0099 (if (cdr file) 0100 (find-file (car file)) 0101 (if (member (concat "." (file-name-extension (buffer-file-name))) sourcepair-header-extensions) 0102 (find-file (concat base-name-no-ext "." kde-prefered-source-extension)) 0103 (find-file (concat base-name-no-ext ".h")))))) 0104 0105 (defun kde-delete-backward-ws () 0106 "Function deletes all preceding whitespace characters." 0107 (interactive) 0108 (let ((start (point)) 0109 end) 0110 (save-excursion 0111 (setq end (re-search-backward "[^ \t]" (point-at-bol) t)) 0112 (if (not end) 0113 (setq end (point-at-bol)) 0114 (setq end (1+ end)))) 0115 (delete-backward-char (- start end)))) 0116 0117 (defun kde-skip-blank-lines () 0118 "Skips backwards past blank lines, stopping 0119 at a first non-blank line" 0120 (let* ((start (point-at-bol)) 0121 (end (point-at-eol)) 0122 (mstring (buffer-substring start end)) 0123 (ret 0)) 0124 (while (or 0125 (string-match "^[ \t\r\n]+$" mstring) 0126 (and (string= mstring "") 0127 (= ret 0))) 0128 (setq ret (forward-line -1)) ; if ret != 0, we stop, since we're at the first line... 0129 (setq start (point-at-bol) 0130 end (point-at-eol)) 0131 (setq mstring (buffer-substring start end)) 0132 ) 0133 )) 0134 0135 (defun kde-comments-begin () 0136 "Skip back from current point past any preceding C-based comments at the beginning of lines. 0137 Presumes no \"/*\" strings are nested within multi-line comments." 0138 (let ((opoint)) 0139 (while (progn (setq opoint (point)) 0140 ;; To previous line 0141 (if (zerop (forward-line -1)) 0142 (cond 0143 ;; If begins with "//" or ends with "*/", then is a 0144 ;; comment. 0145 ((looking-at "[ \t]*\\(//\\|$\\)")) 0146 ((looking-at ".*\\*/[ \t]*$") 0147 (progn (end-of-line) 0148 ;; Avoid //*** single line comments here. 0149 (if (re-search-backward "\\(^\\|[^/]\\)/\\*" nil t) 0150 (progn (beginning-of-line) 0151 (looking-at "[ \t]*/\\*"))))) 0152 (t nil))))) 0153 (goto-char opoint) 0154 ;; Skip past whitespace 0155 (skip-chars-forward " \t\n\r\f") 0156 (beginning-of-line))) 0157 0158 (provide 'kde-emacs-general)