1 ;;; tinylib-ad.el --- Library of adviced functions. Backward compatibility
5 ;; Copyright (C) 1999-2007 Jari Aalto
6 ;; Keywords: extensions
8 ;; Maintainer: Jari Aalto
10 ;; To get information on this program, call M-x tinylib-ad-version
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)
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
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.
29 ;; Visit <http://www.gnu.org/copyleft/gpl.html> for more information
34 ;; ........................................................ &t-install ...
35 ;; Put this file on your Emacs-Lisp load path, add following into your
36 ;; ~/.emacs startup file
38 ;; (require 'tinylibm) ;; Yes, there is no mistake. You require the "m"
43 ;; ..................................................... &t-commentary ...
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.
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.
60 ;; You must not autoload this package; but always include
62 ;; (require 'tinylibm)
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:
68 ;; (require 'tinylib) ;; leave this out
69 ;; (require 'tinyliby) ;; not needed either.
70 ;; (require 'tinylib-ad) ;; not needed either.
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)))
90 (get-buffer shell-command-output-buffer))
91 (with-current-buffer buffer
93 (insert-buffer shell-command-output-buffer)
94 (ti::kill-buffer-safe shell-command-output-buffer))))))
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."
103 (with-current-buffer buffer
108 ;; (define-key-after KEYMAP KEY DEFINITION &optional AFTER)
110 ;; (define-key-after KEYMAP KEY DEFINITION AFTER)
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."
120 ;; 20.4 introduced new arg NOERR
121 ;; (require FEATURE &optional FILE-NAME NOERROR)
123 (unless (string-match "noerr"
124 (or (ti::function-args-p 'require) ""))
126 (around tinylib-ad (feature &optional file-name noerror) act)
127 "Emacs compatibility: Added parameter NOERR."
128 (let* ((noerr (ad-get-arg 2)))
130 (or (featurep feature)
131 (load (or file-name (symbol-name feature)) 'noerr 'nomsg))
134 ;; Emacs includes more arguments
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."
144 (setq ad-return-value (read-char-exclusive))))
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.
149 ;; We instantiate this advice if it can't pass the test.
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))
163 (dolist (ext '(".exe" ".com" ".bat" ".cmd" ".btm" ""))
164 (if (setq ret (ti::file-get-load-path
165 (concat command ext) exec-path))
167 (setq ad-return-value ret))))
171 ;;; ......................................................... &version ...
173 (defconst tinylib-ad-version
174 (substring "$Revision: 2.45 $" 11 15)
175 "Latest version number.")
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.")
181 ;;; ----------------------------------------------------------------------
183 (defun tinylib-ad-version (&optional arg)
184 "Show version information. ARG will instruct to print message to echo area."
186 (ti::package-version-info "tinylib-ad.el" arg))
188 ;;; ----------------------------------------------------------------------
190 (defun tinylib-ad-submit-bug-report ()
193 (ti::package-submit-bug-report
195 tinylib-ad-version-id
196 '(tinylib-ad-version-id)))
200 (provide 'tinylib-ad)
202 ;;; tinylib-ad.el ends here