Fixed.
[riece] / lisp / riece-emacs.el
1 ;;; riece-emacs.el --- FSF Emacs specific functions
2 ;; Copyright (C) 1999 Daiki Ueno
3
4 ;; Author: Daiki Ueno <ueno@unixuser.org>
5 ;; Created: 1999-08-21
6 ;; Keywords: emulation
7
8 ;; This file is part of Riece.
9
10 ;; This program is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; This program is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Code:
26
27 ;;; stolen (and renamed) from gnus-ems.el.
28 ;;; In GNU Emacs, user can intercept whole mouse tracking events by
29 ;;; assigning [mouse-X].  In XEmacs, however, which causes different
30 ;;; effect, that is, the command assigned to [mouse-X] only catches
31 ;;; button-release events.
32 (defvar riece-mouse-2 [mouse-2])
33
34 ;;; popup-menu compatibility stuff, stolen (and renamed) from
35 ;;; semi-def.el.
36 (defmacro riece-popup-menu-bogus-filter-constructor (menu)
37   ;; #### Kludge for FSF Emacs-style menu.
38   (let ((bogus-menu (make-symbol "bogus-menu")))
39     `(let (,bogus-menu selection function)
40        (easy-menu-define ,bogus-menu nil nil ,menu)
41        (setq selection (x-popup-menu t ,bogus-menu))
42        (when selection
43          (setq function (lookup-key ,bogus-menu (apply #'vector selection)))
44          ;; If a callback entry has no name, easy-menu wraps its value.
45          ;; See `easy-menu-make-symbol'.
46          (if (eq t (compare-strings "menu-function-" 0 nil
47                                     (symbol-name function) 0 14))
48              (car (last (symbol-function function)))
49            function)))))
50
51 (defun riece-popup-menu-popup (menu event)
52   (let ((function (riece-popup-menu-bogus-filter-constructor menu)))
53     (if function
54         (funcall function))))
55
56 (defun riece-event-buffer (event)
57   "Return the buffer of the window over which mouse event EVENT occurred."
58   (window-buffer (posn-window (event-start event))))
59
60 (defun riece-event-point (event)
61   "Return the character position of the mouse event EVENT."
62   (posn-point (event-start event)))
63
64 ;;; stolen (and renamed) from gnus-ems.el.
65 (defun riece-region-active-p ()
66   "Say whether the region is active."
67   (and (boundp 'transient-mark-mode)
68        transient-mark-mode
69        (boundp 'mark-active)
70        mark-active))
71
72 (defalias 'riece-make-overlay 'make-overlay)
73 (defalias 'riece-overlay-put 'overlay-put)
74 (defalias 'riece-overlay-start 'overlay-start)
75 (defalias 'riece-overlay-buffer 'overlay-buffer)
76 (defalias 'riece-overlays-in 'overlays-in)
77 (defalias 'riece-delete-overlay 'delete-overlay)
78
79 (defun riece-kill-all-overlays ()
80   "Delete all overlays in the current buffer."
81   (let* ((overlay-lists (overlay-lists))
82          (buffer-read-only nil)
83          (overlays (delq nil (nconc (car overlay-lists) (cdr overlay-lists)))))
84     (while overlays
85       (delete-overlay (car overlays))
86       (setq overlays (cdr overlays)))))
87
88 (defalias 'riece-run-at-time 'run-at-time)
89 (defalias 'riece-run-with-idle-timer 'run-with-idle-timer)
90 (defalias 'riece-cancel-timer 'cancel-timer)
91
92 (defalias 'riece-match-string-no-properties 'match-string-no-properties)
93
94 (defun riece-propertize-modeline-string (string &rest properties)
95   (add-text-properties 0 (length string) properties string)
96   string)
97
98 (defun riece-normalize-modeline-string-1 (string)
99   (if string
100       (if (listp (car string))
101           (cons (car (car string)) (riece-normalize-modeline-string-1
102                                     (append (cdr (car string)) (cdr string))))
103         (cons (car string) (riece-normalize-modeline-string-1
104                             (cdr string))))))
105
106 (defun riece-normalize-modeline-string (string)
107   (if (listp string)
108       (list (apply #'concat (riece-normalize-modeline-string-1 string)))
109     string))
110
111 (defun riece-put-text-property-nonsticky (start end prop value
112                                                      &optional object)
113   (add-text-properties start end
114                        (list prop value 'front-sticky nil 'rear-nonsticky t)
115                        object))
116
117 (defalias 'riece-facep 'facep)
118
119 ;;; stolen (and renamed) from emacsbug.el.
120 (defun riece-recent-messages (n)
121   "Return N most recent messages, most recent first.
122 If N is nil, all messages will be returned."
123   (let ((message-buf (get-buffer "*Messages*")))
124     (if message-buf
125         (with-temp-buffer
126           (let (beg-pos end-pos)
127             (with-current-buffer message-buf
128               (setq end-pos (goto-char (point-max)))
129               (if n
130                   (progn
131                     (forward-line (- n))
132                     (setq beg-pos (point)))
133                 (setq beg-pos (point-min))))
134             (insert-buffer-substring message-buf beg-pos end-pos)
135             (reverse-region (point-min) (point-max))
136             (buffer-string))))))
137
138 (provide 'riece-emacs)
139
140 ;;; riece-emacs.el ends here