From 41099808ae5031e99f5bc3802765e73e701d200f Mon Sep 17 00:00:00 2001 From: teranisi Date: Fri, 4 Feb 2000 03:35:32 +0000 Subject: [PATCH] * poe-18.el (current-time): Fixed leap year count bug. (set-time-zone-rule): New function. (current-time-zone): Use `set-time-zone-rule'. (floor): New function. (window-live-p): New function. (read-from-minibuffer): Redefined to add `HIST' optional argument. (accept-process-output): Redefined to add `TIMEOUT' and `TIMEOUT-MSECS' optional arguments. (get-buffer-window): Redefined to add `FRAME' optional argument. * poe.el (completing-read): Redifined to adjust optional arguments for some emacsen. --- ChangeLog | 15 ++++++++++ poe-18.el | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++-------- poe.el | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 191 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 82290e5..de64e60 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2000-02-04 Yuuichi Teranishi + + * poe-18.el (current-time): Fixed leap year count bug. + (set-time-zone-rule): New function. + (current-time-zone): Use `set-time-zone-rule'. + (floor): New function. + (window-live-p): New function. + (read-from-minibuffer): Redefined to add `HIST' optional argument. + (accept-process-output): Redefined to add `TIMEOUT' and + `TIMEOUT-MSECS' optional arguments. + (get-buffer-window): Redefined to add `FRAME' optional argument. + + * poe.el (completing-read): Redifined to adjust optional arguments + for some emacsen. + 2000-01-31 Mikio Nakajima * poe-18.el (defalias): Remove its definition as a function and diff --git a/poe-18.el b/poe-18.el index 3a7e4e4..d3fc2c5 100644 --- a/poe-18.el +++ b/poe-18.el @@ -230,6 +230,26 @@ Used in `current-time-zone' (Emacs 19 emulating function in poe-18.el).") "*Local timezone name. Used in `current-time-zone' (Emacs 19 emulating function in poe-18.el).") +(defun set-time-zone-rule (tz) + "Set the local time zone using TZ, a string specifying a time zone rule. +If TZ is nil, use implementation-defined default time zone information. +If TZ is t, use Universal Time." + (cond + ((stringp tz) + (setq current-time-local-timezone tz)) + (tz + (setq current-time-local-timezone "GMT")) + (t + (setq current-time-local-timezone + (with-temp-buffer + ;; We use `date' command to get timezone information. + (call-process "date" nil (current-buffer) t) + (goto-char (point-min)) + (if (looking-at + "^.*\\([A-Z][A-Z][A-Z]\\([^ \n\t]*\\)\\).*$") + (buffer-substring (match-beginning 1) + (match-end 1)))))))) + (defun current-time-zone (&optional specified-time) "Return the offset and name for the local time zone. This returns a list of the form (OFFSET NAME). @@ -240,16 +260,10 @@ Optional argument SPECIFIED-TIME is ignored in this implementation. Some operating systems cannot provide all this information to Emacs; in this case, `current-time-zone' returns a list containing nil for the data it can't find." - (let ((local-timezone - (or current-time-local-timezone - (setq current-time-local-timezone - (with-temp-buffer - (call-process "date" nil (current-buffer) t) - (goto-char (point-min)) - (if (looking-at - "^.*\\([A-Z][A-Z][A-Z]\\([^ \n\t]*\\)\\).*$") - (buffer-substring (match-beginning 1) - (match-end 1))))))) + (let ((local-timezone (or current-time-local-timezone + (progn + (set-time-zone-rule nil) + current-time-local-timezone))) timezone abszone seconds) (setq timezone (or (cdr (assoc (upcase local-timezone) @@ -388,8 +402,9 @@ resolution finer than a second." (while (> ct2 65535) (setq ct1 (1+ ct1) ct2 (- ct2 65536)))) - (setq uru (- (+ (- (/ yyyy 4) (/ yyyy 100)) - (/ yyyy 400)) 477)) + (setq year (- yyyy 1)) + (setq uru (- (+ (- (/ year 4) (/ year 100)) + (/ year 400)) 477)) (while (> uru 0) (setq uru (1- uru) i1 (1+ i1) @@ -443,6 +458,14 @@ resolution finer than a second." "Return the absolute value of ARG." (if (< arg 0) (- arg) arg)) +(defun floor (arg &optional divisor) + "Return the largest integer no grater than ARG. +With optional DIVISOR, return the largest integer no greater than ARG/DIVISOR." + (if (null divisor) + (setq divisor 1)) + (if (< arg 0) + (- (/ (- divisor 1 arg) divisor)) + (/ arg divisor))) ;;; @ Basic lisp subroutines. ;;; @@ -523,6 +546,41 @@ even if a buffer with that name exists." "Return non-nil if WINDOW is a minibuffer window." (eq (or window (selected-window)) (minibuffer-window))) +(defun-maybe window-live-p (obj) + "Returns t if OBJECT is a window which is currently visible." + (and (windowp obj) + (or (eq obj (minibuffer-window)) + (eq obj (get-buffer-window (window-buffer obj)))))) + +;; Add optinal argument `hist' +(or (fboundp 'si:read-from-minibuffer) + (progn + (fset 'si:read-from-minibuffer (symbol-function 'read-from-minibuffer)) + (defun read-from-minibuffer (prompt &optional + initial-contents keymap read hist) + + "Read a string from the minibuffer, prompting with string PROMPT. +If optional second arg INITIAL-CONTENTS is non-nil, it is a string + to be inserted into the minibuffer before reading input. + If INITIAL-CONTENTS is (STRING . POSITION), the initial input + is STRING, but point is placed at position POSITION in the minibuffer. +Third arg KEYMAP is a keymap to use whilst reading; + if omitted or nil, the default is `minibuffer-local-map'. +If fourth arg READ is non-nil, then interpret the result as a lisp object + and return that object: + in other words, do `(car (read-from-string INPUT-STRING))' +Fifth arg HIST is ignored in this implementatin." + (si:read-from-minibuffer prompt initial-contents keymap read)))) + +;; Add optional argument `frame'. +(or (fboundp 'si:get-buffer-window) + (progn + (fset 'si:get-buffer-window (symbol-function 'get-buffer-window)) + (defun get-buffer-window (buffer &optional frame) + "Return a window currently displaying BUFFER, or nil if none. +Optional argunemt FRAME is ignored in this implementation." + (si:get-buffer-window buffer)))) + ;;; @@ Environment variables. ;;; @@ -615,6 +673,19 @@ If MATCH is non-nil, mention only file names that match the regexp MATCH. If NOSORT is dummy for compatibility." (si:directory-files directory full match)) +;;; @ Process. +;;; +(or (fboundp 'si:accept-process-output) + (progn + (fset 'si:accept-process-output (symbol-function 'accept-process-output)) + (defun accept-process-output (&optional process timeout timeout-msecs) + "Allow any pending output from subprocesses to be read by Emacs. +It is read into the process' buffers or given to their filter functions. +Non-nil arg PROCESS means do not return until some output has been received + from PROCESS. Nil arg PROCESS means do not return until some output has + been received from any process. +TIMEOUT and TIMEOUT-MSECS are ignored in this implementation." + (si:accept-process-output process)))) ;;; @ Text property. ;;; diff --git a/poe.el b/poe.el index 70d191a..b078bdf 100644 --- a/poe.el +++ b/poe.el @@ -178,6 +178,99 @@ The third arg HISTORY, is dummy for compatibility. See `read-from-minibuffer' for details of HISTORY argument." (si:read-string prompt initial-input))))) +;; (completing-read prompt table &optional +;; FSF Emacs +;; --19.7 : predicate require-match init +;; 19.7 --19.34 : predicate require-match init hist +;; 20.1 -- : predicate require-match init hist def inherit-input-method +;; XEmacs +;; --19.(?): predicate require-match init +;; --21.2 : predicate require-match init hist +;; 21.2 -- : predicate require-match init hist def +;; ) + +;; We support following API. +;; (completing-read prompt table +;; &optional predicate require-match init hist def) +(static-cond + ;; add 'hist' and 'def' argument. + ((< emacs-major-version 19) + (or (fboundp 'si:completing-read) + (progn + (fset 'si:completing-read (symbol-function 'completing-read)) + (defun completing-read + (prompt table &optional predicate require-match init + hist def) + "Read a string in the minibuffer, with completion. +PROMPT is a string to prompt with; normally it ends in a colon and a space. +TABLE is an alist whose elements' cars are strings, or an obarray. +PREDICATE limits completion to a subset of TABLE. +See `try-completion' and `all-completions' for more details + on completion, TABLE, and PREDICATE. + +If REQUIRE-MATCH is non-nil, the user is not allowed to exit unless + the input is (or completes to) an element of TABLE or is null. + If it is also not t, Return does not exit if it does non-null completion. +If the input is null, `completing-read' returns an empty string, + regardless of the value of REQUIRE-MATCH. + +If INIT is non-nil, insert it in the minibuffer initially. + If it is (STRING . POSITION), the initial input + is STRING, but point is placed POSITION characters into the string. +HIST is ignored in this implementation. +DEF, if non-nil, is the default value. + +Completion ignores case if the ambient value of + `completion-ignore-case' is non-nil." + (let ((string (si:completing-read prompt table predicate + require-match init))) + (if (and (string= string "") def) + def string)))))) + ;; add 'def' argument. + ((or (and (featurep 'xemacs) + (or (and (eq emacs-major-version 21) + (< emacs-minor-version 2)) + (< emacs-major-version 21))) + (< emacs-major-version 20)) + (or (fboundp 'si:completing-read) + (progn + (fset 'si:completing-read (symbol-function 'completing-read)) + (defun completing-read + (prompt table &optional predicate require-match init + hist def) + "Read a string in the minibuffer, with completion. +PROMPT is a string to prompt with; normally it ends in a colon and a space. +TABLE is an alist whose elements' cars are strings, or an obarray. +PREDICATE limits completion to a subset of TABLE. +See `try-completion' and `all-completions' for more details + on completion, TABLE, and PREDICATE. + +If REQUIRE-MATCH is non-nil, the user is not allowed to exit unless + the input is (or completes to) an element of TABLE or is null. + If it is also not t, Return does not exit if it does non-null completion. +If the input is null, `completing-read' returns an empty string, + regardless of the value of REQUIRE-MATCH. + +If INIT is non-nil, insert it in the minibuffer initially. + If it is (STRING . POSITION), the initial input + is STRING, but point is placed POSITION characters into the string. +HIST, if non-nil, specifies a history list + and optionally the initial position in the list. + It can be a symbol, which is the history list variable to use, + or it can be a cons cell (HISTVAR . HISTPOS). + In that case, HISTVAR is the history list variable to use, + and HISTPOS is the initial position (the position in the list + which INIT corresponds to). + Positions are counted starting from 1 at the beginning of the list. +DEF, if non-nil, is the default value. + +Completion ignores case if the ambient value of + `completion-ignore-case' is non-nil." + (let ((string (si:completing-read prompt table predicate + require-match init hist))) + (if (and (string= string "") def) + def string))))))) + ;; v18: (string-to-int STRING) ;; v19: (string-to-number STRING) ;; v20: (string-to-number STRING &optional BASE) -- 1.7.10.4