]> git.donarmstrong.com Git - lib.git/blob - emacs_el/tiny-tools/tiny/tinylib-ad.el
f7a26a89020db637c0a1407ebd3a192a79fc61a8
[lib.git] / emacs_el / tiny-tools / tiny / tinylib-ad.el
1 ;;; tinylib-ad.el --- Library of adviced functions. Backward compatibility
2
3 ;;{{{ Id
4
5 ;; Copyright (C)    1999-2007 Jari Aalto
6 ;; Keywords:        extensions
7 ;; Author:          Jari Aalto
8 ;; Maintainer:      Jari Aalto
9 ;;
10 ;; To get information on this program, call M-x tinylib-ad-version
11
12 ;; COPYRIGHT NOTICE
13 ;;
14 ;; This program is free software; you can redistribute it and/or modify it
15 ;; under the terms of the GNU General Public License as published by the Free
16 ;; Software Foundation; either version 2 of the License, or (at your option)
17 ;; any later version.
18 ;;
19 ;; This program is distributed in the hope that it will be useful, but
20 ;; WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 ;; or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
22 ;; for more details.
23 ;;
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with program; see the file COPYING. If not, write to the
26 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
27 ;; Boston, MA 02110-1301, USA.
28 ;;
29 ;; Visit <http://www.gnu.org/copyleft/gpl.html> for more information
30
31 ;;}}}
32 ;;{{{ Install
33
34 ;; ........................................................ &t-install ...
35 ;; Put this file on your Emacs-Lisp load path, add following into your
36 ;; ~/.emacs startup file
37 ;;
38 ;;      (require 'tinylibm)    ;; Yes, there is no mistake. You require the "m"
39
40 ;;}}}
41 ;;{{{ Documentation
42
43 ;; ..................................................... &t-commentary ...
44
45 ;;; Commentary:
46
47 ;;  Preface, 1999
48 ;;
49 ;;      This is lisp function library, package itself does nothing.
50 ;;      It modifies existing Emacs functions with advice.el in order
51 ;;      to provide backward compatibility for functions that have changed.
52 ;;      E.g. Emacs 20.4 introduced new parameter NOERR to `require' command.
53 ;;
54 ;;      There is another way, load this library first and continue using
55 ;;      your current Emacs version. This package will redefine functions
56 ;;      only when needed, so it should be quite safe.
57 ;;
58 ;;  Usage
59 ;;
60 ;;      You must not autoload this package; but always include
61 ;;
62 ;;          (require 'tinylibm)
63 ;;
64 ;;      You don't need any other require commands: all other library
65 ;;      functions get defined as well by using autoload. Repeat: you don't
66 ;;      have to put these in your packages:
67 ;;
68 ;;          (require 'tinylib)     ;; leave this out
69 ;;          (require 'tinyliby)    ;; not needed either.
70 ;;          (require 'tinylib-ad)  ;; not needed either.
71
72 ;;}}}
73
74 ;;; Change Log:
75
76 ;;; Code:
77
78 (require 'tinylibb)
79
80 (eval-when-compile
81   (require 'advice))
82
83 (when (and (ti::emacs-p)
84            (not (ti::emacs-p "20.2")))
85   (defadvice shell-command (after tiny act)
86     "The OUTPUT-BUFFER does not work in old releases. Fix it."
87     (let* ((buffer (ad-get-arg 1)))
88       (when (and buffer
89                  (get-buffer buffer)
90                  (get-buffer shell-command-output-buffer))
91         (with-current-buffer buffer
92           (erase-buffer)
93           (insert-buffer shell-command-output-buffer)
94           (ti::kill-buffer-safe shell-command-output-buffer))))))
95
96 ;; Emacs 20.1 inroduced new argument (buffer-size &optional BUFFER)
97 (unless (string-match "buffer"
98                       (or (ti::function-args-p 'buffer-size) ""))
99   (defadvice buffer-size
100     (around tinylib-ad (feature &optional buffer) act)
101     "Emacs compatibility: optional parameter BUFFER."
102     (if buffer
103         (with-current-buffer buffer
104           ad-do-it)
105       ad-do-it)))
106
107 ;;  Emacs 21.1
108 ;;  (define-key-after KEYMAP KEY DEFINITION &optional AFTER)
109 ;;  Emacs 20.7
110 ;;  (define-key-after KEYMAP KEY DEFINITION AFTER)
111
112 (when (and (fboundp 'define-key-after)
113            (string-match "optional"
114                          (or (ti::function-args-p 'define-key-after) "")))
115   (defadvice define-key-after
116     (around tinylib-ad (keymap key definition &optional after) act)
117     "Emacs compatibility: parameter AFTER is now optional."
118     ad-do-it))
119
120 ;; 20.4 introduced new arg NOERR
121 ;; (require FEATURE &optional FILE-NAME NOERROR)
122
123 (unless (string-match "noerr"
124                       (or (ti::function-args-p 'require) ""))
125   (defadvice require
126     (around tinylib-ad (feature &optional file-name noerror) act)
127     "Emacs compatibility: Added parameter NOERR."
128     (let* ((noerr (ad-get-arg 2)))
129       (if noerr
130           (or (featurep feature)
131               (load (or file-name (symbol-name feature)) 'noerr 'nomsg))
132         ad-do-it))))
133
134 ;; Emacs includes more arguments
135
136 (when (and (fboundp 'read-char-exclusive)
137            (not (string-match "prompt"
138                               (or (ti::function-args-p 'read-char-exclusive) ""))))
139   (defadvice read-char-exclusive
140     (around tinylib-ad (&optional prompt inherit-input-method) act)
141     "Emacs compatibility. Added parameters PROMPT INHERIT-INPUT-METHOD,
142 but INHERIT-INPUT-METHOD is not supported."
143     (message prompt)
144     (setq ad-return-value (read-char-exclusive))))
145
146 ;; Older versions of `executable-find' did not search ".exe" or ".com" ...
147 ;; extensions. This was true for XEmacs 21.2 also. In Emacs 20.4 it's ok.
148 ;;
149 ;; We instantiate this advice if it can't pass the test.
150
151 (when (and (ti::win32-p)
152            ;;  Try and see if  executable-find adds extension .com and
153            ;;  .exe, if these fail, then fix it.
154            (let ((exec-path exec-path))
155              (push "c:/windows" exec-path)
156              (push "c:/winnt" exec-path)
157              (null (or (executable-find "command")
158                        (executable-find "cmd")))))
159   (defadvice executable-find (around tinylib-ad act)
160     "Replace function. In win32, try also extension .com .exe .bat ..."
161     (let ((command (ad-get-arg 0))
162           ret)
163       (dolist (ext '(".exe" ".com" ".bat" ".cmd" ".btm" ""))
164         (if (setq ret (ti::file-get-load-path
165                        (concat command ext) exec-path))
166             (return ret)))
167       (setq ad-return-value ret))))
168
169 ;;{{{ Version
170
171 ;;; ......................................................... &version ...
172
173 (defconst tinylib-ad-version
174   (substring "$Revision: 2.45 $" 11 15)
175   "Latest version number.")
176
177 (defconst tinylib-ad-version-id
178   "$Id: tinylib-ad.el,v 2.45 2007/05/01 17:20:44 jaalto Exp $"
179   "Latest modification time and version number.")
180
181 ;;; ----------------------------------------------------------------------
182 ;;;
183 (defun tinylib-ad-version (&optional arg)
184   "Show version information. ARG will instruct to print message to echo area."
185   (interactive "P")
186   (ti::package-version-info "tinylib-ad.el" arg))
187
188 ;;; ----------------------------------------------------------------------
189 ;;;
190 (defun tinylib-ad-submit-bug-report ()
191   "Submit bug report."
192   (interactive)
193   (ti::package-submit-bug-report
194    "tinylib-ad.el"
195    tinylib-ad-version-id
196    '(tinylib-ad-version-id)))
197
198 ;;}}}
199
200 (provide   'tinylib-ad)
201
202 ;;; tinylib-ad.el ends here