diff options
| author | Juanma Barranquero | 2003-05-30 23:24:41 +0000 |
|---|---|---|
| committer | Juanma Barranquero | 2003-05-30 23:24:41 +0000 |
| commit | db47d2ab7a8fb71f995539b33d4c1ec1d1019f07 (patch) | |
| tree | 24a21220da5fe216c59fa47ad34a2449f9725e4f | |
| parent | 17cd3083a59cde81052603790db330b3d71ebdea (diff) | |
| download | emacs-db47d2ab7a8fb71f995539b33d4c1ec1d1019f07.tar.gz emacs-db47d2ab7a8fb71f995539b33d4c1ec1d1019f07.zip | |
Moved to obsolete/.
| -rw-r--r-- | lisp/emacs-lisp/float.el | 458 | ||||
| -rw-r--r-- | lisp/options.el | 147 | ||||
| -rw-r--r-- | lisp/textmodes/scribe.el | 324 |
3 files changed, 0 insertions, 929 deletions
diff --git a/lisp/emacs-lisp/float.el b/lisp/emacs-lisp/float.el deleted file mode 100644 index e5d71abb69b..00000000000 --- a/lisp/emacs-lisp/float.el +++ /dev/null | |||
| @@ -1,458 +0,0 @@ | |||
| 1 | ;;; float.el --- obsolete floating point arithmetic package | ||
| 2 | |||
| 3 | ;; Copyright (C) 1986 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | ;; Author: Bill Rosenblatt | ||
| 6 | ;; Maintainer: FSF | ||
| 7 | ;; Keywords: extensions | ||
| 8 | |||
| 9 | ;; This file is part of GNU Emacs. | ||
| 10 | |||
| 11 | ;; GNU Emacs is free software; you can redistribute it and/or modify | ||
| 12 | ;; it under the terms of the GNU General Public License as published by | ||
| 13 | ;; the Free Software Foundation; either version 2, or (at your option) | ||
| 14 | ;; any later version. | ||
| 15 | |||
| 16 | ;; GNU Emacs is distributed in the hope that it will be useful, | ||
| 17 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 18 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 19 | ;; GNU General Public License for more details. | ||
| 20 | |||
| 21 | ;; You should have received a copy of the GNU General Public License | ||
| 22 | ;; along with GNU Emacs; see the file COPYING. If not, write to the | ||
| 23 | ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
| 24 | ;; Boston, MA 02111-1307, USA. | ||
| 25 | |||
| 26 | ;;; Commentary: | ||
| 27 | |||
| 28 | ;; Floating point numbers are represented by dot-pairs (mant . exp) | ||
| 29 | ;; where mant is the 24-bit signed integral mantissa and exp is the | ||
| 30 | ;; base 2 exponent. | ||
| 31 | ;; | ||
| 32 | ;; Emacs LISP supports a 24-bit signed integer data type, which has a | ||
| 33 | ;; range of -(2**23) to +(2**23)-1, or -8388608 to 8388607 decimal. | ||
| 34 | ;; This gives six significant decimal digit accuracy. Exponents can | ||
| 35 | ;; be anything in the range -(2**23) to +(2**23)-1. | ||
| 36 | ;; | ||
| 37 | ;; User interface: | ||
| 38 | ;; function f converts from integer to floating point | ||
| 39 | ;; function string-to-float converts from string to floating point | ||
| 40 | ;; function fint converts a floating point to integer (with truncation) | ||
| 41 | ;; function float-to-string converts from floating point to string | ||
| 42 | ;; | ||
| 43 | ;; Caveats: | ||
| 44 | ;; - Exponents outside of the range of +/-100 or so will cause certain | ||
| 45 | ;; functions (especially conversion routines) to take forever. | ||
| 46 | ;; - Very little checking is done for fixed point overflow/underflow. | ||
| 47 | ;; - No checking is done for over/underflow of the exponent | ||
| 48 | ;; (hardly necessary when exponent can be 2**23). | ||
| 49 | ;; | ||
| 50 | ;; | ||
| 51 | ;; Bill Rosenblatt | ||
| 52 | ;; June 20, 1986 | ||
| 53 | ;; | ||
| 54 | |||
| 55 | ;;; Code: | ||
| 56 | |||
| 57 | ;; fundamental implementation constants | ||
| 58 | (defconst exp-base 2 | ||
| 59 | "Base of exponent in this floating point representation.") | ||
| 60 | |||
| 61 | (defconst mantissa-bits 24 | ||
| 62 | "Number of significant bits in this floating point representation.") | ||
| 63 | |||
| 64 | (defconst decimal-digits 6 | ||
| 65 | "Number of decimal digits expected to be accurate.") | ||
| 66 | |||
| 67 | (defconst expt-digits 2 | ||
| 68 | "Maximum permitted digits in a scientific notation exponent.") | ||
| 69 | |||
| 70 | ;; other constants | ||
| 71 | (defconst maxbit (1- mantissa-bits) | ||
| 72 | "Number of highest bit") | ||
| 73 | |||
| 74 | (defconst mantissa-maxval (1- (ash 1 maxbit)) | ||
| 75 | "Maximum permissible value of mantissa") | ||
| 76 | |||
| 77 | (defconst mantissa-minval (ash 1 maxbit) | ||
| 78 | "Minimum permissible value of mantissa") | ||
| 79 | |||
| 80 | (defconst floating-point-regexp | ||
| 81 | "^[ \t]*\\(-?\\)\\([0-9]*\\)\ | ||
| 82 | \\(\\.\\([0-9]*\\)\\|\\)\ | ||
| 83 | \\(\\(\\([Ee]\\)\\(-?\\)\\([0-9][0-9]*\\)\\)\\|\\)[ \t]*$" | ||
| 84 | "Regular expression to match floating point numbers. Extract matches: | ||
| 85 | 1 - minus sign | ||
| 86 | 2 - integer part | ||
| 87 | 4 - fractional part | ||
| 88 | 8 - minus sign for power of ten | ||
| 89 | 9 - power of ten | ||
| 90 | ") | ||
| 91 | |||
| 92 | (defconst high-bit-mask (ash 1 maxbit) | ||
| 93 | "Masks all bits except the high-order (sign) bit.") | ||
| 94 | |||
| 95 | (defconst second-bit-mask (ash 1 (1- maxbit)) | ||
| 96 | "Masks all bits except the highest-order magnitude bit") | ||
| 97 | |||
| 98 | ;; various useful floating point constants | ||
| 99 | (defconst _f0 '(0 . 1)) | ||
| 100 | |||
| 101 | (defconst _f1/2 '(4194304 . -23)) | ||
| 102 | |||
| 103 | (defconst _f1 '(4194304 . -22)) | ||
| 104 | |||
| 105 | (defconst _f10 '(5242880 . -19)) | ||
| 106 | |||
| 107 | ;; support for decimal conversion routines | ||
| 108 | (defvar powers-of-10 (make-vector (1+ decimal-digits) _f1)) | ||
| 109 | (aset powers-of-10 1 _f10) | ||
| 110 | (aset powers-of-10 2 '(6553600 . -16)) | ||
| 111 | (aset powers-of-10 3 '(8192000 . -13)) | ||
| 112 | (aset powers-of-10 4 '(5120000 . -9)) | ||
| 113 | (aset powers-of-10 5 '(6400000 . -6)) | ||
| 114 | (aset powers-of-10 6 '(8000000 . -3)) | ||
| 115 | |||
| 116 | (defconst all-decimal-digs-minval (aref powers-of-10 (1- decimal-digits))) | ||
| 117 | (defconst highest-power-of-10 (aref powers-of-10 decimal-digits)) | ||
| 118 | |||
| 119 | (defun fashl (fnum) ; floating-point arithmetic shift left | ||
| 120 | (cons (ash (car fnum) 1) (1- (cdr fnum)))) | ||
| 121 | |||
| 122 | (defun fashr (fnum) ; floating point arithmetic shift right | ||
| 123 | (cons (ash (car fnum) -1) (1+ (cdr fnum)))) | ||
| 124 | |||
| 125 | (defun normalize (fnum) | ||
| 126 | (if (> (car fnum) 0) ; make sure next-to-highest bit is set | ||
| 127 | (while (zerop (logand (car fnum) second-bit-mask)) | ||
| 128 | (setq fnum (fashl fnum))) | ||
| 129 | (if (< (car fnum) 0) ; make sure highest bit is set | ||
| 130 | (while (zerop (logand (car fnum) high-bit-mask)) | ||
| 131 | (setq fnum (fashl fnum))) | ||
| 132 | (setq fnum _f0))) ; "standard 0" | ||
| 133 | fnum) | ||
| 134 | |||
| 135 | (defun abs (n) ; integer absolute value | ||
| 136 | (if (>= n 0) n (- n))) | ||
| 137 | |||
| 138 | (defun fabs (fnum) ; re-normalize after taking abs value | ||
| 139 | (normalize (cons (abs (car fnum)) (cdr fnum)))) | ||
| 140 | |||
| 141 | (defun xor (a b) ; logical exclusive or | ||
| 142 | (and (or a b) (not (and a b)))) | ||
| 143 | |||
| 144 | (defun same-sign (a b) ; two f-p numbers have same sign? | ||
| 145 | (not (xor (natnump (car a)) (natnump (car b))))) | ||
| 146 | |||
| 147 | (defun extract-match (str i) ; used after string-match | ||
| 148 | (condition-case () | ||
| 149 | (substring str (match-beginning i) (match-end i)) | ||
| 150 | (error ""))) | ||
| 151 | |||
| 152 | ;; support for the multiplication function | ||
| 153 | (defconst halfword-bits (/ mantissa-bits 2)) ; bits in a halfword | ||
| 154 | (defconst masklo (1- (ash 1 halfword-bits))) ; isolate the lower halfword | ||
| 155 | (defconst maskhi (lognot masklo)) ; isolate the upper halfword | ||
| 156 | (defconst round-limit (ash 1 (/ halfword-bits 2))) | ||
| 157 | |||
| 158 | (defun hihalf (n) ; return high halfword, shifted down | ||
| 159 | (ash (logand n maskhi) (- halfword-bits))) | ||
| 160 | |||
| 161 | (defun lohalf (n) ; return low halfword | ||
| 162 | (logand n masklo)) | ||
| 163 | |||
| 164 | ;; Visible functions | ||
| 165 | |||
| 166 | ;; Arithmetic functions | ||
| 167 | (defun f+ (a1 a2) | ||
| 168 | "Returns the sum of two floating point numbers." | ||
| 169 | (let ((f1 (fmax a1 a2)) | ||
| 170 | (f2 (fmin a1 a2))) | ||
| 171 | (if (same-sign a1 a2) | ||
| 172 | (setq f1 (fashr f1) ; shift right to avoid overflow | ||
| 173 | f2 (fashr f2))) | ||
| 174 | (normalize | ||
| 175 | (cons (+ (car f1) (ash (car f2) (- (cdr f2) (cdr f1)))) | ||
| 176 | (cdr f1))))) | ||
| 177 | |||
| 178 | (defun f- (a1 &optional a2) ; unary or binary minus | ||
| 179 | "Returns the difference of two floating point numbers." | ||
| 180 | (if a2 | ||
| 181 | (f+ a1 (f- a2)) | ||
| 182 | (normalize (cons (- (car a1)) (cdr a1))))) | ||
| 183 | |||
| 184 | (defun f* (a1 a2) ; multiply in halfword chunks | ||
| 185 | "Returns the product of two floating point numbers." | ||
| 186 | (let* ((i1 (car (fabs a1))) | ||
| 187 | (i2 (car (fabs a2))) | ||
| 188 | (sign (not (same-sign a1 a2))) | ||
| 189 | (prodlo (+ (hihalf (* (lohalf i1) (lohalf i2))) | ||
| 190 | (lohalf (* (hihalf i1) (lohalf i2))) | ||
| 191 | (lohalf (* (lohalf i1) (hihalf i2))))) | ||
| 192 | (prodhi (+ (* (hihalf i1) (hihalf i2)) | ||
| 193 | (hihalf (* (hihalf i1) (lohalf i2))) | ||
| 194 | (hihalf (* (lohalf i1) (hihalf i2))) | ||
| 195 | (hihalf prodlo)))) | ||
| 196 | (if (> (lohalf prodlo) round-limit) | ||
| 197 | (setq prodhi (1+ prodhi))) ; round off truncated bits | ||
| 198 | (normalize | ||
| 199 | (cons (if sign (- prodhi) prodhi) | ||
| 200 | (+ (cdr (fabs a1)) (cdr (fabs a2)) mantissa-bits))))) | ||
| 201 | |||
| 202 | (defun f/ (a1 a2) ; SLOW subtract-and-shift algorithm | ||
| 203 | "Returns the quotient of two floating point numbers." | ||
| 204 | (if (zerop (car a2)) ; if divide by 0 | ||
| 205 | (signal 'arith-error (list "attempt to divide by zero" a1 a2)) | ||
| 206 | (let ((bits (1- maxbit)) | ||
| 207 | (quotient 0) | ||
| 208 | (dividend (car (fabs a1))) | ||
| 209 | (divisor (car (fabs a2))) | ||
| 210 | (sign (not (same-sign a1 a2)))) | ||
| 211 | (while (natnump bits) | ||
| 212 | (if (< (- dividend divisor) 0) | ||
| 213 | (setq quotient (ash quotient 1)) | ||
| 214 | (setq quotient (1+ (ash quotient 1)) | ||
| 215 | dividend (- dividend divisor))) | ||
| 216 | (setq dividend (ash dividend 1) | ||
| 217 | bits (1- bits))) | ||
| 218 | (normalize | ||
| 219 | (cons (if sign (- quotient) quotient) | ||
| 220 | (- (cdr (fabs a1)) (cdr (fabs a2)) (1- maxbit))))))) | ||
| 221 | |||
| 222 | (defun f% (a1 a2) | ||
| 223 | "Returns the remainder of first floating point number divided by second." | ||
| 224 | (f- a1 (f* (ftrunc (f/ a1 a2)) a2))) | ||
| 225 | |||
| 226 | |||
| 227 | ;; Comparison functions | ||
| 228 | (defun f= (a1 a2) | ||
| 229 | "Returns t if two floating point numbers are equal, nil otherwise." | ||
| 230 | (equal a1 a2)) | ||
| 231 | |||
| 232 | (defun f> (a1 a2) | ||
| 233 | "Returns t if first floating point number is greater than second, | ||
| 234 | nil otherwise." | ||
| 235 | (cond ((and (natnump (car a1)) (< (car a2) 0)) | ||
| 236 | t) ; a1 nonnegative, a2 negative | ||
| 237 | ((and (> (car a1) 0) (<= (car a2) 0)) | ||
| 238 | t) ; a1 positive, a2 nonpositive | ||
| 239 | ((and (<= (car a1) 0) (natnump (car a2))) | ||
| 240 | nil) ; a1 nonpos, a2 nonneg | ||
| 241 | ((/= (cdr a1) (cdr a2)) ; same signs. exponents differ | ||
| 242 | (> (cdr a1) (cdr a2))) ; compare the mantissas. | ||
| 243 | (t | ||
| 244 | (> (car a1) (car a2))))) ; same exponents. | ||
| 245 | |||
| 246 | (defun f>= (a1 a2) | ||
| 247 | "Returns t if first floating point number is greater than or equal to | ||
| 248 | second, nil otherwise." | ||
| 249 | (or (f> a1 a2) (f= a1 a2))) | ||
| 250 | |||
| 251 | (defun f< (a1 a2) | ||
| 252 | "Returns t if first floating point number is less than second, | ||
| 253 | nil otherwise." | ||
| 254 | (not (f>= a1 a2))) | ||
| 255 | |||
| 256 | (defun f<= (a1 a2) | ||
| 257 | "Returns t if first floating point number is less than or equal to | ||
| 258 | second, nil otherwise." | ||
| 259 | (not (f> a1 a2))) | ||
| 260 | |||
| 261 | (defun f/= (a1 a2) | ||
| 262 | "Returns t if first floating point number is not equal to second, | ||
| 263 | nil otherwise." | ||
| 264 | (not (f= a1 a2))) | ||
| 265 | |||
| 266 | (defun fmin (a1 a2) | ||
| 267 | "Returns the minimum of two floating point numbers." | ||
| 268 | (if (f< a1 a2) a1 a2)) | ||
| 269 | |||
| 270 | (defun fmax (a1 a2) | ||
| 271 | "Returns the maximum of two floating point numbers." | ||
| 272 | (if (f> a1 a2) a1 a2)) | ||
| 273 | |||
| 274 | (defun fzerop (fnum) | ||
| 275 | "Returns t if the floating point number is zero, nil otherwise." | ||
| 276 | (= (car fnum) 0)) | ||
| 277 | |||
| 278 | (defun floatp (fnum) | ||
| 279 | "Returns t if the arg is a floating point number, nil otherwise." | ||
| 280 | (and (consp fnum) (integerp (car fnum)) (integerp (cdr fnum)))) | ||
| 281 | |||
| 282 | ;; Conversion routines | ||
| 283 | (defun f (int) | ||
| 284 | "Convert the integer argument to floating point, like a C cast operator." | ||
| 285 | (normalize (cons int '0))) | ||
| 286 | |||
| 287 | (defun int-to-hex-string (int) | ||
| 288 | "Convert the integer argument to a C-style hexadecimal string." | ||
| 289 | (let ((shiftval -20) | ||
| 290 | (str "0x") | ||
| 291 | (hex-chars "0123456789ABCDEF")) | ||
| 292 | (while (<= shiftval 0) | ||
| 293 | (setq str (concat str (char-to-string | ||
| 294 | (aref hex-chars | ||
| 295 | (logand (lsh int shiftval) 15)))) | ||
| 296 | shiftval (+ shiftval 4))) | ||
| 297 | str)) | ||
| 298 | |||
| 299 | (defun ftrunc (fnum) ; truncate fractional part | ||
| 300 | "Truncate the fractional part of a floating point number." | ||
| 301 | (cond ((natnump (cdr fnum)) ; it's all integer, return number as is | ||
| 302 | fnum) | ||
| 303 | ((<= (cdr fnum) (- maxbit)) ; it's all fractional, return 0 | ||
| 304 | '(0 . 1)) | ||
| 305 | (t ; otherwise mask out fractional bits | ||
| 306 | (let ((mant (car fnum)) (exp (cdr fnum))) | ||
| 307 | (normalize | ||
| 308 | (cons (if (natnump mant) ; if negative, use absolute value | ||
| 309 | (ash (ash mant exp) (- exp)) | ||
| 310 | (- (ash (ash (- mant) exp) (- exp)))) | ||
| 311 | exp)))))) | ||
| 312 | |||
| 313 | (defun fint (fnum) ; truncate and convert to integer | ||
| 314 | "Convert the floating point number to integer, with truncation, | ||
| 315 | like a C cast operator." | ||
| 316 | (let* ((tf (ftrunc fnum)) (tint (car tf)) (texp (cdr tf))) | ||
| 317 | (cond ((>= texp mantissa-bits) ; too high, return "maxint" | ||
| 318 | mantissa-maxval) | ||
| 319 | ((<= texp (- mantissa-bits)) ; too low, return "minint" | ||
| 320 | mantissa-minval) | ||
| 321 | (t ; in range | ||
| 322 | (ash tint texp))))) ; shift so that exponent is 0 | ||
| 323 | |||
| 324 | (defun float-to-string (fnum &optional sci) | ||
| 325 | "Convert the floating point number to a decimal string. | ||
| 326 | Optional second argument non-nil means use scientific notation." | ||
| 327 | (let* ((value (fabs fnum)) (sign (< (car fnum) 0)) | ||
| 328 | (power 0) (result 0) (str "") | ||
| 329 | (temp 0) (pow10 _f1)) | ||
| 330 | |||
| 331 | (if (f= fnum _f0) | ||
| 332 | "0" | ||
| 333 | (if (f>= value _f1) ; find largest power of 10 <= value | ||
| 334 | (progn ; value >= 1, power is positive | ||
| 335 | (while (f<= (setq temp (f* pow10 highest-power-of-10)) value) | ||
| 336 | (setq pow10 temp | ||
| 337 | power (+ power decimal-digits))) | ||
| 338 | (while (f<= (setq temp (f* pow10 _f10)) value) | ||
| 339 | (setq pow10 temp | ||
| 340 | power (1+ power)))) | ||
| 341 | (progn ; value < 1, power is negative | ||
| 342 | (while (f> (setq temp (f/ pow10 highest-power-of-10)) value) | ||
| 343 | (setq pow10 temp | ||
| 344 | power (- power decimal-digits))) | ||
| 345 | (while (f> pow10 value) | ||
| 346 | (setq pow10 (f/ pow10 _f10) | ||
| 347 | power (1- power))))) | ||
| 348 | ; get value in range 100000 to 999999 | ||
| 349 | (setq value (f* (f/ value pow10) all-decimal-digs-minval) | ||
| 350 | result (ftrunc value)) | ||
| 351 | (let (int) | ||
| 352 | (if (f> (f- value result) _f1/2) ; round up if remainder > 0.5 | ||
| 353 | (setq int (1+ (fint result))) | ||
| 354 | (setq int (fint result))) | ||
| 355 | (setq str (int-to-string int)) | ||
| 356 | (if (>= int 1000000) | ||
| 357 | (setq power (1+ power)))) | ||
| 358 | |||
| 359 | (if sci ; scientific notation | ||
| 360 | (setq str (concat (substring str 0 1) "." (substring str 1) | ||
| 361 | "E" (int-to-string power))) | ||
| 362 | |||
| 363 | ; regular decimal string | ||
| 364 | (cond ((>= power (1- decimal-digits)) | ||
| 365 | ; large power, append zeroes | ||
| 366 | (let ((zeroes (- power decimal-digits))) | ||
| 367 | (while (natnump zeroes) | ||
| 368 | (setq str (concat str "0") | ||
| 369 | zeroes (1- zeroes))))) | ||
| 370 | |||
| 371 | ; negative power, prepend decimal | ||
| 372 | ((< power 0) ; point and zeroes | ||
| 373 | (let ((zeroes (- (- power) 2))) | ||
| 374 | (while (natnump zeroes) | ||
| 375 | (setq str (concat "0" str) | ||
| 376 | zeroes (1- zeroes))) | ||
| 377 | (setq str (concat "0." str)))) | ||
| 378 | |||
| 379 | (t ; in range, insert decimal point | ||
| 380 | (setq str (concat | ||
| 381 | (substring str 0 (1+ power)) | ||
| 382 | "." | ||
| 383 | (substring str (1+ power))))))) | ||
| 384 | |||
| 385 | (if sign ; if negative, prepend minus sign | ||
| 386 | (concat "-" str) | ||
| 387 | str)))) | ||
| 388 | |||
| 389 | |||
| 390 | ;; string to float conversion. | ||
| 391 | ;; accepts scientific notation, but ignores anything after the first two | ||
| 392 | ;; digits of the exponent. | ||
| 393 | (defun string-to-float (str) | ||
| 394 | "Convert the string to a floating point number. | ||
| 395 | Accepts a decimal string in scientific notation, with exponent preceded | ||
| 396 | by either E or e. Only the six most significant digits of the integer | ||
| 397 | and fractional parts are used; only the first two digits of the exponent | ||
| 398 | are used. Negative signs preceding both the decimal number and the exponent | ||
| 399 | are recognized." | ||
| 400 | |||
| 401 | (if (string-match floating-point-regexp str 0) | ||
| 402 | (let (power) | ||
| 403 | (f* | ||
| 404 | ; calculate the mantissa | ||
| 405 | (let* ((int-subst (extract-match str 2)) | ||
| 406 | (fract-subst (extract-match str 4)) | ||
| 407 | (digit-string (concat int-subst fract-subst)) | ||
| 408 | (mant-sign (equal (extract-match str 1) "-")) | ||
| 409 | (leading-0s 0) (round-up nil)) | ||
| 410 | |||
| 411 | ; get rid of leading 0's | ||
| 412 | (setq power (- (length int-subst) decimal-digits)) | ||
| 413 | (while (and (< leading-0s (length digit-string)) | ||
| 414 | (= (aref digit-string leading-0s) ?0)) | ||
| 415 | (setq leading-0s (1+ leading-0s))) | ||
| 416 | (setq power (- power leading-0s) | ||
| 417 | digit-string (substring digit-string leading-0s)) | ||
| 418 | |||
| 419 | ; if more than 6 digits, round off | ||
| 420 | (if (> (length digit-string) decimal-digits) | ||
| 421 | (setq round-up (>= (aref digit-string decimal-digits) ?5) | ||
| 422 | digit-string (substring digit-string 0 decimal-digits)) | ||
| 423 | (setq power (+ power (- decimal-digits (length digit-string))))) | ||
| 424 | |||
| 425 | ; round up and add minus sign, if necessary | ||
| 426 | (f (* (+ (string-to-int digit-string) | ||
| 427 | (if round-up 1 0)) | ||
| 428 | (if mant-sign -1 1)))) | ||
| 429 | |||
| 430 | ; calculate the exponent (power of ten) | ||
| 431 | (let* ((expt-subst (extract-match str 9)) | ||
| 432 | (expt-sign (equal (extract-match str 8) "-")) | ||
| 433 | (expt 0) (chunks 0) (tens 0) (exponent _f1) | ||
| 434 | (func 'f*)) | ||
| 435 | |||
| 436 | (setq expt (+ (* (string-to-int | ||
| 437 | (substring expt-subst 0 | ||
| 438 | (min expt-digits (length expt-subst)))) | ||
| 439 | (if expt-sign -1 1)) | ||
| 440 | power)) | ||
| 441 | (if (< expt 0) ; if power of 10 negative | ||
| 442 | (setq expt (- expt) ; take abs val of exponent | ||
| 443 | func 'f/)) ; and set up to divide, not multiply | ||
| 444 | |||
| 445 | (setq chunks (/ expt decimal-digits) | ||
| 446 | tens (% expt decimal-digits)) | ||
| 447 | ; divide or multiply by "chunks" of 10**6 | ||
| 448 | (while (> chunks 0) | ||
| 449 | (setq exponent (funcall func exponent highest-power-of-10) | ||
| 450 | chunks (1- chunks))) | ||
| 451 | ; divide or multiply by remaining power of ten | ||
| 452 | (funcall func exponent (aref powers-of-10 tens))))) | ||
| 453 | |||
| 454 | _f0)) ; if invalid, return 0 | ||
| 455 | |||
| 456 | (provide 'float) | ||
| 457 | |||
| 458 | ;;; float.el ends here | ||
diff --git a/lisp/options.el b/lisp/options.el deleted file mode 100644 index 53a67516b2f..00000000000 --- a/lisp/options.el +++ /dev/null | |||
| @@ -1,147 +0,0 @@ | |||
| 1 | ;;; options.el --- edit Options command for Emacs | ||
| 2 | |||
| 3 | ;; Copyright (C) 1985 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | ;; Maintainer: FSF | ||
| 6 | |||
| 7 | ;; This file is part of GNU Emacs. | ||
| 8 | |||
| 9 | ;; GNU Emacs is free software; you can redistribute it and/or modify | ||
| 10 | ;; it under the terms of the GNU General Public License as published by | ||
| 11 | ;; the Free Software Foundation; either version 2, or (at your option) | ||
| 12 | ;; any later version. | ||
| 13 | |||
| 14 | ;; GNU Emacs is distributed in the hope that it will be useful, | ||
| 15 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 17 | ;; GNU General Public License for more details. | ||
| 18 | |||
| 19 | ;; You should have received a copy of the GNU General Public License | ||
| 20 | ;; along with GNU Emacs; see the file COPYING. If not, write to the | ||
| 21 | ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
| 22 | ;; Boston, MA 02111-1307, USA. | ||
| 23 | |||
| 24 | ;;; Commentary: | ||
| 25 | |||
| 26 | ;; This code provides functions to list and edit the values of all global | ||
| 27 | ;; option variables known to loaded Emacs Lisp code. There are two entry | ||
| 28 | ;; points, `list-options' and `edit' options'. The latter enters a major | ||
| 29 | ;; mode specifically for editing option values. Do `M-x describe-mode' in | ||
| 30 | ;; that context for more details. | ||
| 31 | |||
| 32 | ;; The customization buffer feature is intended to make this obsolete. | ||
| 33 | |||
| 34 | ;;; Code: | ||
| 35 | |||
| 36 | ;;;###autoload | ||
| 37 | (defun list-options () | ||
| 38 | "Display a list of Emacs user options, with values and documentation. | ||
| 39 | It is now better to use Customize instead." | ||
| 40 | (interactive) | ||
| 41 | (with-output-to-temp-buffer "*List Options*" | ||
| 42 | (let (vars) | ||
| 43 | (mapatoms (function (lambda (sym) | ||
| 44 | (if (user-variable-p sym) | ||
| 45 | (setq vars (cons sym vars)))))) | ||
| 46 | (setq vars (sort vars 'string-lessp)) | ||
| 47 | (while vars | ||
| 48 | (let ((sym (car vars))) | ||
| 49 | (when (boundp sym) | ||
| 50 | (princ ";; ") | ||
| 51 | (prin1 sym) | ||
| 52 | (princ ":\n\t") | ||
| 53 | (prin1 (symbol-value sym)) | ||
| 54 | (terpri) | ||
| 55 | (princ (substitute-command-keys | ||
| 56 | (documentation-property sym 'variable-documentation))) | ||
| 57 | (princ "\n;;\n")) | ||
| 58 | (setq vars (cdr vars)))) | ||
| 59 | (with-current-buffer "*List Options*" | ||
| 60 | (Edit-options-mode) | ||
| 61 | (setq buffer-read-only t))))) | ||
| 62 | |||
| 63 | ;;;###autoload | ||
| 64 | (defun edit-options () | ||
| 65 | "Edit a list of Emacs user option values. | ||
| 66 | Selects a buffer containing such a list, | ||
| 67 | in which there are commands to set the option values. | ||
| 68 | Type \\[describe-mode] in that buffer for a list of commands. | ||
| 69 | |||
| 70 | The Custom feature is intended to make this obsolete." | ||
| 71 | (interactive) | ||
| 72 | (list-options) | ||
| 73 | (pop-to-buffer "*List Options*")) | ||
| 74 | |||
| 75 | (defvar Edit-options-mode-map | ||
| 76 | (let ((map (make-keymap))) | ||
| 77 | (define-key map "s" 'Edit-options-set) | ||
| 78 | (define-key map "x" 'Edit-options-toggle) | ||
| 79 | (define-key map "1" 'Edit-options-t) | ||
| 80 | (define-key map "0" 'Edit-options-nil) | ||
| 81 | (define-key map "p" 'backward-paragraph) | ||
| 82 | (define-key map " " 'forward-paragraph) | ||
| 83 | (define-key map "n" 'forward-paragraph) | ||
| 84 | map) | ||
| 85 | "") | ||
| 86 | |||
| 87 | ;; Edit Options mode is suitable only for specially formatted data. | ||
| 88 | (put 'Edit-options-mode 'mode-class 'special) | ||
| 89 | |||
| 90 | (defun Edit-options-mode () | ||
| 91 | "\\<Edit-options-mode-map>\ | ||
| 92 | Major mode for editing Emacs user option settings. | ||
| 93 | Special commands are: | ||
| 94 | \\[Edit-options-set] -- set variable point points at. New value read using minibuffer. | ||
| 95 | \\[Edit-options-toggle] -- toggle variable, t -> nil, nil -> t. | ||
| 96 | \\[Edit-options-t] -- set variable to t. | ||
| 97 | \\[Edit-options-nil] -- set variable to nil. | ||
| 98 | Changed values made by these commands take effect immediately. | ||
| 99 | |||
| 100 | Each variable description is a paragraph. | ||
| 101 | For convenience, the characters \\[backward-paragraph] and \\[forward-paragraph] move back and forward by paragraphs." | ||
| 102 | (kill-all-local-variables) | ||
| 103 | (set-syntax-table emacs-lisp-mode-syntax-table) | ||
| 104 | (use-local-map Edit-options-mode-map) | ||
| 105 | (make-local-variable 'paragraph-separate) | ||
| 106 | (setq paragraph-separate "[^\^@-\^?]") | ||
| 107 | (make-local-variable 'paragraph-start) | ||
| 108 | (setq paragraph-start "\t") | ||
| 109 | (setq truncate-lines t) | ||
| 110 | (setq major-mode 'Edit-options-mode) | ||
| 111 | (setq mode-name "Options") | ||
| 112 | (run-hooks 'Edit-options-mode-hook)) | ||
| 113 | |||
| 114 | (defun Edit-options-set () (interactive) | ||
| 115 | (Edit-options-modify | ||
| 116 | (lambda (var) (eval-minibuffer (concat "New " (symbol-name var) ": "))))) | ||
| 117 | |||
| 118 | (defun Edit-options-toggle () (interactive) | ||
| 119 | (Edit-options-modify (lambda (var) (not (symbol-value var))))) | ||
| 120 | |||
| 121 | (defun Edit-options-t () (interactive) | ||
| 122 | (Edit-options-modify (lambda (var) t))) | ||
| 123 | |||
| 124 | (defun Edit-options-nil () (interactive) | ||
| 125 | (Edit-options-modify (lambda (var) nil))) | ||
| 126 | |||
| 127 | (defun Edit-options-modify (modfun) | ||
| 128 | (save-excursion | ||
| 129 | (let ((buffer-read-only nil) var pos) | ||
| 130 | (re-search-backward "^;; \\|\\`") | ||
| 131 | (forward-char 3) | ||
| 132 | (setq pos (point)) | ||
| 133 | (save-restriction | ||
| 134 | (narrow-to-region pos (progn (end-of-line) (1- (point)))) | ||
| 135 | (goto-char pos) | ||
| 136 | (setq var (read (current-buffer)))) | ||
| 137 | (goto-char pos) | ||
| 138 | (forward-line 1) | ||
| 139 | (forward-char 1) | ||
| 140 | (save-excursion | ||
| 141 | (set var (funcall modfun var))) | ||
| 142 | (kill-sexp 1) | ||
| 143 | (prin1 (symbol-value var) (current-buffer))))) | ||
| 144 | |||
| 145 | (provide 'options) | ||
| 146 | |||
| 147 | ;;; options.el ends here | ||
diff --git a/lisp/textmodes/scribe.el b/lisp/textmodes/scribe.el deleted file mode 100644 index 16067d19638..00000000000 --- a/lisp/textmodes/scribe.el +++ /dev/null | |||
| @@ -1,324 +0,0 @@ | |||
| 1 | ;;; scribe.el --- scribe mode, and its idiosyncratic commands | ||
| 2 | |||
| 3 | ;; Copyright (C) 1985 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | ;; Maintainer: FSF | ||
| 6 | ;; Keywords: wp | ||
| 7 | |||
| 8 | ;; This file is part of GNU Emacs. | ||
| 9 | |||
| 10 | ;; GNU Emacs 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 | ;; GNU Emacs 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 | ;;; Commentary: | ||
| 26 | |||
| 27 | ;; A major mode for editing source in written for the Scribe text formatter. | ||
| 28 | ;; Knows about Scribe syntax and standard layout rules. The command to | ||
| 29 | ;; run Scribe on a buffer is bogus; someone interested should fix it. | ||
| 30 | |||
| 31 | ;;; Code: | ||
| 32 | |||
| 33 | (defgroup scribe nil | ||
| 34 | "Scribe mode." | ||
| 35 | :prefix "scribe-" | ||
| 36 | :group 'wp) | ||
| 37 | |||
| 38 | (defvar scribe-mode-syntax-table nil | ||
| 39 | "Syntax table used while in scribe mode.") | ||
| 40 | |||
| 41 | (defvar scribe-mode-abbrev-table nil | ||
| 42 | "Abbrev table used while in scribe mode.") | ||
| 43 | |||
| 44 | (defcustom scribe-fancy-paragraphs nil | ||
| 45 | "*Non-nil makes Scribe mode use a different style of paragraph separation." | ||
| 46 | :type 'boolean | ||
| 47 | :group 'scribe) | ||
| 48 | |||
| 49 | (defcustom scribe-electric-quote nil | ||
| 50 | "*Non-nil makes insert of double quote use `` or '' depending on context." | ||
| 51 | :type 'boolean | ||
| 52 | :group 'scribe) | ||
| 53 | |||
| 54 | (defcustom scribe-electric-parenthesis nil | ||
| 55 | "*Non-nil makes parenthesis char ( (]}> ) automatically insert its close | ||
| 56 | if typed after an @Command form." | ||
| 57 | :type 'boolean | ||
| 58 | :group 'scribe) | ||
| 59 | |||
| 60 | (defconst scribe-open-parentheses "[({<" | ||
| 61 | "Open parenthesis characters for Scribe.") | ||
| 62 | |||
| 63 | (defconst scribe-close-parentheses "])}>" | ||
| 64 | "Close parenthesis characters for Scribe. | ||
| 65 | These should match up with `scribe-open-parenthesis'.") | ||
| 66 | |||
| 67 | (if (null scribe-mode-syntax-table) | ||
| 68 | (let ((st (syntax-table))) | ||
| 69 | (unwind-protect | ||
| 70 | (progn | ||
| 71 | (setq scribe-mode-syntax-table (copy-syntax-table | ||
| 72 | text-mode-syntax-table)) | ||
| 73 | (set-syntax-table scribe-mode-syntax-table) | ||
| 74 | (modify-syntax-entry ?\" " ") | ||
| 75 | (modify-syntax-entry ?\\ " ") | ||
| 76 | (modify-syntax-entry ?@ "w ") | ||
| 77 | (modify-syntax-entry ?< "(> ") | ||
| 78 | (modify-syntax-entry ?> ")< ") | ||
| 79 | (modify-syntax-entry ?[ "(] ") | ||
| 80 | (modify-syntax-entry ?] ")[ ") | ||
| 81 | (modify-syntax-entry ?{ "(} ") | ||
| 82 | (modify-syntax-entry ?} "){ ") | ||
| 83 | (modify-syntax-entry ?' "w ")) | ||
| 84 | (set-syntax-table st)))) | ||
| 85 | |||
| 86 | (defvar scribe-mode-map nil) | ||
| 87 | |||
| 88 | (if scribe-mode-map | ||
| 89 | nil | ||
| 90 | (setq scribe-mode-map (make-sparse-keymap)) | ||
| 91 | (define-key scribe-mode-map "\t" 'scribe-tab) | ||
| 92 | (define-key scribe-mode-map "\e\t" 'tab-to-tab-stop) | ||
| 93 | (define-key scribe-mode-map "\es" 'center-line) | ||
| 94 | (define-key scribe-mode-map "\e}" 'up-list) | ||
| 95 | (define-key scribe-mode-map "\eS" 'center-paragraph) | ||
| 96 | (define-key scribe-mode-map "\"" 'scribe-insert-quote) | ||
| 97 | (define-key scribe-mode-map "(" 'scribe-parenthesis) | ||
| 98 | (define-key scribe-mode-map "[" 'scribe-parenthesis) | ||
| 99 | (define-key scribe-mode-map "{" 'scribe-parenthesis) | ||
| 100 | (define-key scribe-mode-map "<" 'scribe-parenthesis) | ||
| 101 | (define-key scribe-mode-map "\C-c\C-c" 'scribe-chapter) | ||
| 102 | (define-key scribe-mode-map "\C-c\C-t" 'scribe-section) | ||
| 103 | (define-key scribe-mode-map "\C-c\C-s" 'scribe-subsection) | ||
| 104 | (define-key scribe-mode-map "\C-c\C-v" 'scribe-insert-environment) | ||
| 105 | (define-key scribe-mode-map "\C-c\C-e" 'scribe-bracket-region-be) | ||
| 106 | (define-key scribe-mode-map "\C-c[" 'scribe-begin) | ||
| 107 | (define-key scribe-mode-map "\C-c]" 'scribe-end) | ||
| 108 | (define-key scribe-mode-map "\C-c\C-i" 'scribe-italicize-word) | ||
| 109 | (define-key scribe-mode-map "\C-c\C-b" 'scribe-bold-word) | ||
| 110 | (define-key scribe-mode-map "\C-c\C-u" 'scribe-underline-word)) | ||
| 111 | |||
| 112 | ;;;###autoload | ||
| 113 | (define-derived-mode scribe-mode text-mode "Scribe" | ||
| 114 | "Major mode for editing files of Scribe (a text formatter) source. | ||
| 115 | Scribe-mode is similar to text-mode, with a few extra commands added. | ||
| 116 | \\{scribe-mode-map} | ||
| 117 | |||
| 118 | Interesting variables: | ||
| 119 | |||
| 120 | `scribe-fancy-paragraphs' | ||
| 121 | Non-nil makes Scribe mode use a different style of paragraph separation. | ||
| 122 | |||
| 123 | `scribe-electric-quote' | ||
| 124 | Non-nil makes insert of double quote use `` or '' depending on context. | ||
| 125 | |||
| 126 | `scribe-electric-parenthesis' | ||
| 127 | Non-nil makes an open-parenthesis char (one of `([<{') | ||
| 128 | automatically insert its close if typed after an @Command form." | ||
| 129 | (set (make-local-variable 'comment-start) "@Comment[") | ||
| 130 | (set (make-local-variable 'comment-start-skip) (concat "@Comment[" scribe-open-parentheses "]")) | ||
| 131 | (set (make-local-variable 'comment-column) 0) | ||
| 132 | (set (make-local-variable 'comment-end) "]") | ||
| 133 | (set (make-local-variable 'paragraph-start) | ||
| 134 | (concat "\\([\n\f]\\)\\|\\(@\\w+[" | ||
| 135 | scribe-open-parentheses | ||
| 136 | "].*[" | ||
| 137 | scribe-close-parentheses | ||
| 138 | "]$\\)")) | ||
| 139 | (set (make-local-variable 'paragraph-separate) | ||
| 140 | (if scribe-fancy-paragraphs paragraph-start "$")) | ||
| 141 | (set (make-local-variable 'sentence-end) | ||
| 142 | "\\([.?!]\\|@:\\)[]\"')}]*\\($\\| $\\|\t\\| \\)[ \t\n]*") | ||
| 143 | (set (make-local-variable 'compile-command) | ||
| 144 | (concat "scribe " (buffer-file-name)))) | ||
| 145 | |||
| 146 | (defun scribe-tab () | ||
| 147 | (interactive) | ||
| 148 | (insert "@\\")) | ||
| 149 | |||
| 150 | ;; This algorithm could probably be improved somewhat. | ||
| 151 | ;; Right now, it loses seriously... | ||
| 152 | |||
| 153 | (defun scribe () | ||
| 154 | "Run Scribe on the current buffer." | ||
| 155 | (interactive) | ||
| 156 | (call-interactively 'compile)) | ||
| 157 | |||
| 158 | (defun scribe-envelop-word (string count) | ||
| 159 | "Surround current word with Scribe construct @STRING[...]. | ||
| 160 | COUNT specifies how many words to surround. A negative count means | ||
| 161 | to skip backward." | ||
| 162 | (let ((spos (point)) (epos (point)) (ccoun 0) noparens) | ||
| 163 | (if (not (zerop count)) | ||
| 164 | (progn (if (= (char-syntax (preceding-char)) ?w) | ||
| 165 | (forward-sexp (min -1 count))) | ||
| 166 | (setq spos (point)) | ||
| 167 | (if (looking-at (concat "@\\w[" scribe-open-parentheses "]")) | ||
| 168 | (forward-char 2) | ||
| 169 | (goto-char epos) | ||
| 170 | (skip-chars-backward "\\W") | ||
| 171 | (forward-char -1)) | ||
| 172 | (forward-sexp (max count 1)) | ||
| 173 | (setq epos (point)))) | ||
| 174 | (goto-char spos) | ||
| 175 | (while (and (< ccoun (length scribe-open-parentheses)) | ||
| 176 | (save-excursion | ||
| 177 | (or (search-forward (char-to-string | ||
| 178 | (aref scribe-open-parentheses ccoun)) | ||
| 179 | epos t) | ||
| 180 | (search-forward (char-to-string | ||
| 181 | (aref scribe-close-parentheses ccoun)) | ||
| 182 | epos t))) | ||
| 183 | (setq ccoun (1+ ccoun)))) | ||
| 184 | (if (>= ccoun (length scribe-open-parentheses)) | ||
| 185 | (progn (goto-char epos) | ||
| 186 | (insert "@end(" string ")") | ||
| 187 | (goto-char spos) | ||
| 188 | (insert "@begin(" string ")")) | ||
| 189 | (goto-char epos) | ||
| 190 | (insert (aref scribe-close-parentheses ccoun)) | ||
| 191 | (goto-char spos) | ||
| 192 | (insert "@" string (aref scribe-open-parentheses ccoun)) | ||
| 193 | (goto-char epos) | ||
| 194 | (forward-char 3) | ||
| 195 | (skip-chars-forward scribe-close-parentheses)))) | ||
| 196 | |||
| 197 | (defun scribe-underline-word (count) | ||
| 198 | "Underline COUNT words around point by means of Scribe constructs." | ||
| 199 | (interactive "p") | ||
| 200 | (scribe-envelop-word "u" count)) | ||
| 201 | |||
| 202 | (defun scribe-bold-word (count) | ||
| 203 | "Boldface COUNT words around point by means of Scribe constructs." | ||
| 204 | (interactive "p") | ||
| 205 | (scribe-envelop-word "b" count)) | ||
| 206 | |||
| 207 | (defun scribe-italicize-word (count) | ||
| 208 | "Italicize COUNT words around point by means of Scribe constructs." | ||
| 209 | (interactive "p") | ||
| 210 | (scribe-envelop-word "i" count)) | ||
| 211 | |||
| 212 | (defun scribe-begin () | ||
| 213 | (interactive) | ||
| 214 | (insert "\n") | ||
| 215 | (forward-char -1) | ||
| 216 | (scribe-envelop-word "Begin" 0) | ||
| 217 | (re-search-forward (concat "[" scribe-open-parentheses "]"))) | ||
| 218 | |||
| 219 | (defun scribe-end () | ||
| 220 | (interactive) | ||
| 221 | (insert "\n") | ||
| 222 | (forward-char -1) | ||
| 223 | (scribe-envelop-word "End" 0) | ||
| 224 | (re-search-forward (concat "[" scribe-open-parentheses "]"))) | ||
| 225 | |||
| 226 | (defun scribe-chapter () | ||
| 227 | (interactive) | ||
| 228 | (insert "\n") | ||
| 229 | (forward-char -1) | ||
| 230 | (scribe-envelop-word "Chapter" 0) | ||
| 231 | (re-search-forward (concat "[" scribe-open-parentheses "]"))) | ||
| 232 | |||
| 233 | (defun scribe-section () | ||
| 234 | (interactive) | ||
| 235 | (insert "\n") | ||
| 236 | (forward-char -1) | ||
| 237 | (scribe-envelop-word "Section" 0) | ||
| 238 | (re-search-forward (concat "[" scribe-open-parentheses "]"))) | ||
| 239 | |||
| 240 | (defun scribe-subsection () | ||
| 241 | (interactive) | ||
| 242 | (insert "\n") | ||
| 243 | (forward-char -1) | ||
| 244 | (scribe-envelop-word "SubSection" 0) | ||
| 245 | (re-search-forward (concat "[" scribe-open-parentheses "]"))) | ||
| 246 | |||
| 247 | (defun scribe-bracket-region-be (env min max) | ||
| 248 | (interactive "sEnvironment: \nr") | ||
| 249 | (save-excursion | ||
| 250 | (goto-char max) | ||
| 251 | (insert "@end(" env ")\n") | ||
| 252 | (goto-char min) | ||
| 253 | (insert "@begin(" env ")\n"))) | ||
| 254 | |||
| 255 | (defun scribe-insert-environment (env) | ||
| 256 | (interactive "sEnvironment: ") | ||
| 257 | (scribe-bracket-region-be env (point) (point)) | ||
| 258 | (forward-line 1) | ||
| 259 | (insert ?\n) | ||
| 260 | (forward-char -1)) | ||
| 261 | |||
| 262 | (defun scribe-insert-quote (count) | ||
| 263 | "Insert ``, '' or \" according to preceding character. | ||
| 264 | If `scribe-electric-quote' is non-nil, insert ``, '' or \" according | ||
| 265 | to preceding character. With numeric arg N, always insert N \" characters. | ||
| 266 | Else just insert \"." | ||
| 267 | (interactive "P") | ||
| 268 | (if (or count (not scribe-electric-quote)) | ||
| 269 | (self-insert-command (prefix-numeric-value count)) | ||
| 270 | (let (lastfore lastback lastquote) | ||
| 271 | (insert | ||
| 272 | (cond | ||
| 273 | ((= (preceding-char) ?\\) ?\") | ||
| 274 | ((bobp) "``") | ||
| 275 | (t | ||
| 276 | (setq lastfore (save-excursion (and (search-backward | ||
| 277 | "``" (- (point) 1000) t) | ||
| 278 | (point))) | ||
| 279 | lastback (save-excursion (and (search-backward | ||
| 280 | "''" (- (point) 1000) t) | ||
| 281 | (point))) | ||
| 282 | lastquote (save-excursion (and (search-backward | ||
| 283 | "\"" (- (point) 100) t) | ||
| 284 | (point)))) | ||
| 285 | (if (not lastquote) | ||
| 286 | (cond ((not lastfore) "``") | ||
| 287 | ((not lastback) "''") | ||
| 288 | ((> lastfore lastback) "''") | ||
| 289 | (t "``")) | ||
| 290 | (cond ((and (not lastback) (not lastfore)) "\"") | ||
| 291 | ((and lastback (not lastfore) (> lastquote lastback)) "\"") | ||
| 292 | ((and lastback (not lastfore) (> lastback lastquote)) "``") | ||
| 293 | ((and lastfore (not lastback) (> lastquote lastfore)) "\"") | ||
| 294 | ((and lastfore (not lastback) (> lastfore lastquote)) "''") | ||
| 295 | ((and (> lastquote lastfore) (> lastquote lastback)) "\"") | ||
| 296 | ((> lastfore lastback) "''") | ||
| 297 | (t "``"))))))))) | ||
| 298 | |||
| 299 | (defun scribe-parenthesis (count) | ||
| 300 | "If scribe-electric-parenthesis is non-nil, insertion of an open-parenthesis | ||
| 301 | character inserts the following close parenthesis character if the | ||
| 302 | preceding text is of the form @Command." | ||
| 303 | (interactive "P") | ||
| 304 | (self-insert-command (prefix-numeric-value count)) | ||
| 305 | (let (at-command paren-char point-save) | ||
| 306 | (if (or count (not scribe-electric-parenthesis)) | ||
| 307 | nil | ||
| 308 | (save-excursion | ||
| 309 | (forward-char -1) | ||
| 310 | (setq point-save (point)) | ||
| 311 | (skip-chars-backward (concat "^ \n\t\f" scribe-open-parentheses)) | ||
| 312 | (setq at-command (and (equal (following-char) ?@) | ||
| 313 | (/= (point) (1- point-save))))) | ||
| 314 | (if (and at-command | ||
| 315 | (setq paren-char | ||
| 316 | (string-match (regexp-quote | ||
| 317 | (char-to-string (preceding-char))) | ||
| 318 | scribe-open-parentheses))) | ||
| 319 | (save-excursion | ||
| 320 | (insert (aref scribe-close-parentheses paren-char))))))) | ||
| 321 | |||
| 322 | (provide 'scribe) | ||
| 323 | |||
| 324 | ;;; scribe.el ends here | ||