aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1995-08-27 17:50:39 +0000
committerRichard M. Stallman1995-08-27 17:50:39 +0000
commitc31afdbda4c33d57085ebce3e09543a5d3c0be2f (patch)
treef48c05f1bae1e787e359ed3ae723d76f1cd486e1
parent539fbabbec620feb085d48c90ae98e5ebd8b77c9 (diff)
downloademacs-c31afdbda4c33d57085ebce3e09543a5d3c0be2f.tar.gz
emacs-c31afdbda4c33d57085ebce3e09543a5d3c0be2f.zip
Load cl only during compilation.
(edmacro-mismatch, edmacro-subseq): New functions. Use them instead of mismatch and subseq.
-rw-r--r--lisp/edmacro.el92
1 files changed, 72 insertions, 20 deletions
diff --git a/lisp/edmacro.el b/lisp/edmacro.el
index 0255a675072..1cf9a104d98 100644
--- a/lisp/edmacro.el
+++ b/lisp/edmacro.el
@@ -69,7 +69,8 @@
69 69
70;;; Code: 70;;; Code:
71 71
72(require 'cl) 72(eval-when-compile
73 (require 'cl))
73 74
74;;; The user-level commands for editing macros. 75;;; The user-level commands for editing macros.
75 76
@@ -221,7 +222,7 @@ or nil, use a compact 80-column format."
221 (let ((str (buffer-substring (match-beginning 1) 222 (let ((str (buffer-substring (match-beginning 1)
222 (match-end 1)))) 223 (match-end 1))))
223 (unless (equal str "") 224 (unless (equal str "")
224 (setq cmd (and (not (equalp str "none")) 225 (setq cmd (and (not (equal str "none"))
225 (intern str))) 226 (intern str)))
226 (and (fboundp cmd) (not (arrayp (symbol-function cmd))) 227 (and (fboundp cmd) (not (arrayp (symbol-function cmd)))
227 (not (y-or-n-p 228 (not (y-or-n-p
@@ -236,7 +237,7 @@ or nil, use a compact 80-column format."
236 (buffer-substring (match-beginning 1) 237 (buffer-substring (match-beginning 1)
237 (match-end 1))))) 238 (match-end 1)))))
238 (unless (equal key "") 239 (unless (equal key "")
239 (if (equalp key "none") 240 (if (equal key "none")
240 (setq no-keys t) 241 (setq no-keys t)
241 (push key keys) 242 (push key keys)
242 (let ((b (key-binding key))) 243 (let ((b (key-binding key)))
@@ -405,14 +406,14 @@ doubt, use whitespace."
405 (let* ((prefix 406 (let* ((prefix
406 (or (and (integerp (aref rest-mac 0)) 407 (or (and (integerp (aref rest-mac 0))
407 (memq (aref rest-mac 0) mdigs) 408 (memq (aref rest-mac 0) mdigs)
408 (memq (key-binding (subseq rest-mac 0 1)) 409 (memq (key-binding (edmacro-subseq rest-mac 0 1))
409 '(digit-argument negative-argument)) 410 '(digit-argument negative-argument))
410 (let ((i 1)) 411 (let ((i 1))
411 (while (memq (aref rest-mac i) (cdr mdigs)) 412 (while (memq (aref rest-mac i) (cdr mdigs))
412 (incf i)) 413 (incf i))
413 (and (not (memq (aref rest-mac i) pkeys)) 414 (and (not (memq (aref rest-mac i) pkeys))
414 (prog1 (concat "M-" (subseq rest-mac 0 i) " ") 415 (prog1 (concat "M-" (edmacro-subseq rest-mac 0 i) " ")
415 (callf subseq rest-mac i))))) 416 (callf edmacro-subseq rest-mac i)))))
416 (and (eq (aref rest-mac 0) ?\C-u) 417 (and (eq (aref rest-mac 0) ?\C-u)
417 (eq (key-binding [?\C-u]) 'universal-argument) 418 (eq (key-binding [?\C-u]) 'universal-argument)
418 (let ((i 1)) 419 (let ((i 1))
@@ -420,7 +421,7 @@ doubt, use whitespace."
420 (incf i)) 421 (incf i))
421 (and (not (memq (aref rest-mac i) pkeys)) 422 (and (not (memq (aref rest-mac i) pkeys))
422 (prog1 (loop repeat i concat "C-u ") 423 (prog1 (loop repeat i concat "C-u ")
423 (callf subseq rest-mac i))))) 424 (callf edmacro-subseq rest-mac i)))))
424 (and (eq (aref rest-mac 0) ?\C-u) 425 (and (eq (aref rest-mac 0) ?\C-u)
425 (eq (key-binding [?\C-u]) 'universal-argument) 426 (eq (key-binding [?\C-u]) 'universal-argument)
426 (let ((i 1)) 427 (let ((i 1))
@@ -430,18 +431,18 @@ doubt, use whitespace."
430 '(?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9)) 431 '(?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9))
431 (incf i)) 432 (incf i))
432 (and (not (memq (aref rest-mac i) pkeys)) 433 (and (not (memq (aref rest-mac i) pkeys))
433 (prog1 (concat "C-u " (subseq rest-mac 1 i) " ") 434 (prog1 (concat "C-u " (edmacro-subseq rest-mac 1 i) " ")
434 (callf subseq rest-mac i))))))) 435 (callf edmacro-subseq rest-mac i)))))))
435 (bind-len (apply 'max 1 436 (bind-len (apply 'max 1
436 (loop for map in maps 437 (loop for map in maps
437 for b = (lookup-key map rest-mac) 438 for b = (lookup-key map rest-mac)
438 when b collect b))) 439 when b collect b)))
439 (key (subseq rest-mac 0 bind-len)) 440 (key (edmacro-subseq rest-mac 0 bind-len))
440 (fkey nil) tlen tkey 441 (fkey nil) tlen tkey
441 (bind (or (loop for map in maps for b = (lookup-key map key) 442 (bind (or (loop for map in maps for b = (lookup-key map key)
442 thereis (and (not (integerp b)) b)) 443 thereis (and (not (integerp b)) b))
443 (and (setq fkey (lookup-key function-key-map rest-mac)) 444 (and (setq fkey (lookup-key function-key-map rest-mac))
444 (setq tlen fkey tkey (subseq rest-mac 0 tlen) 445 (setq tlen fkey tkey (edmacro-subseq rest-mac 0 tlen)
445 fkey (lookup-key function-key-map tkey)) 446 fkey (lookup-key function-key-map tkey))
446 (loop for map in maps 447 (loop for map in maps
447 for b = (lookup-key map fkey) 448 for b = (lookup-key map fkey)
@@ -467,7 +468,7 @@ doubt, use whitespace."
467 (> first 32) (<= first maxkey) (/= first 92) 468 (> first 32) (<= first maxkey) (/= first 92)
468 (progn 469 (progn
469 (if (> text 30) (setq text 30)) 470 (if (> text 30) (setq text 30))
470 (setq desc (concat (subseq rest-mac 0 text))) 471 (setq desc (concat (edmacro-subseq rest-mac 0 text)))
471 (when (string-match "^[ACHMsS]-." desc) 472 (when (string-match "^[ACHMsS]-." desc)
472 (setq text 2) 473 (setq text 2)
473 (callf substring desc 0 2)) 474 (callf substring desc 0 2))
@@ -484,7 +485,7 @@ doubt, use whitespace."
484 (> text bind-len) 485 (> text bind-len)
485 (memq (aref rest-mac text) '(return 13)) 486 (memq (aref rest-mac text) '(return 13))
486 (progn 487 (progn
487 (setq desc (concat (subseq rest-mac bind-len text))) 488 (setq desc (concat (edmacro-subseq rest-mac bind-len text)))
488 (commandp (intern-soft desc)))) 489 (commandp (intern-soft desc))))
489 (if (commandp (intern-soft desc)) (setq bind desc)) 490 (if (commandp (intern-soft desc)) (setq bind desc))
490 (setq desc (format "<<%s>>" desc)) 491 (setq desc (format "<<%s>>" desc))
@@ -521,15 +522,14 @@ doubt, use whitespace."
521 (if prefix (setq desc (concat prefix desc))) 522 (if prefix (setq desc (concat prefix desc)))
522 (unless (string-match " " desc) 523 (unless (string-match " " desc)
523 (let ((times 1) (pos bind-len)) 524 (let ((times 1) (pos bind-len))
524 (while (not (mismatch rest-mac rest-mac 525 (while (not (edmacro-mismatch rest-mac rest-mac
525 :end1 bind-len :start2 pos 526 0 bind-len pos (+ bind-len pos)))
526 :end2 (+ bind-len pos)))
527 (incf times) 527 (incf times)
528 (incf pos bind-len)) 528 (incf pos bind-len))
529 (when (> times 1) 529 (when (> times 1)
530 (setq desc (format "%d*%s" times desc)) 530 (setq desc (format "%d*%s" times desc))
531 (setq bind-len (* bind-len times))))) 531 (setq bind-len (* bind-len times)))))
532 (setq rest-mac (subseq rest-mac bind-len)) 532 (setq rest-mac (edmacro-subseq rest-mac bind-len))
533 (if verbose 533 (if verbose
534 (progn 534 (progn
535 (unless (equal res "") (callf concat res "\n")) 535 (unless (equal res "") (callf concat res "\n"))
@@ -550,15 +550,67 @@ doubt, use whitespace."
550 (incf len (length desc))))) 550 (incf len (length desc)))))
551 res)) 551 res))
552 552
553(defun edmacro-mismatch (cl-seq1 cl-seq2 cl-start1 cl-end1 cl-start2 cl-end2)
554 "Compare SEQ1 with SEQ2, return index of first mismatching element.
555Return nil if the sequences match. If one sequence is a prefix of the
556other, the return value indicates the end of the shorted sequence."
557 (let (cl-test cl-test-not cl-key cl-from-end)
558 (or cl-end1 (setq cl-end1 (length cl-seq1)))
559 (or cl-end2 (setq cl-end2 (length cl-seq2)))
560 (if cl-from-end
561 (progn
562 (while (and (< cl-start1 cl-end1) (< cl-start2 cl-end2)
563 (cl-check-match (elt cl-seq1 (1- cl-end1))
564 (elt cl-seq2 (1- cl-end2))))
565 (setq cl-end1 (1- cl-end1) cl-end2 (1- cl-end2)))
566 (and (or (< cl-start1 cl-end1) (< cl-start2 cl-end2))
567 (1- cl-end1)))
568 (let ((cl-p1 (and (listp cl-seq1) (nthcdr cl-start1 cl-seq1)))
569 (cl-p2 (and (listp cl-seq2) (nthcdr cl-start2 cl-seq2))))
570 (while (and (< cl-start1 cl-end1) (< cl-start2 cl-end2)
571 (cl-check-match (if cl-p1 (car cl-p1)
572 (aref cl-seq1 cl-start1))
573 (if cl-p2 (car cl-p2)
574 (aref cl-seq2 cl-start2))))
575 (setq cl-p1 (cdr cl-p1) cl-p2 (cdr cl-p2)
576 cl-start1 (1+ cl-start1) cl-start2 (1+ cl-start2)))
577 (and (or (< cl-start1 cl-end1) (< cl-start2 cl-end2))
578 cl-start1)))))
579
580(defun edmacro-subseq (seq start &optional end)
581 "Return the subsequence of SEQ from START to END.
582If END is omitted, it defaults to the length of the sequence.
583If START or END is negative, it counts from the end."
584 (if (stringp seq) (substring seq start end)
585 (let (len)
586 (and end (< end 0) (setq end (+ end (setq len (length seq)))))
587 (if (< start 0) (setq start (+ start (or len (setq len (length seq))))))
588 (cond ((listp seq)
589 (if (> start 0) (setq seq (nthcdr start seq)))
590 (if end
591 (let ((res nil))
592 (while (>= (setq end (1- end)) start)
593 (cl-push (cl-pop seq) res))
594 (nreverse res))
595 (copy-sequence seq)))
596 (t
597 (or end (setq end (or len (length seq))))
598 (let ((res (make-vector (max (- end start) 0) nil))
599 (i 0))
600 (while (< start end)
601 (aset res i (aref seq start))
602 (setq i (1+ i) start (1+ start)))
603 res))))))
604
553(defun edmacro-fix-menu-commands (macro) 605(defun edmacro-fix-menu-commands (macro)
554 (when (vectorp macro) 606 (when (vectorp macro)
555 (let ((i 0) ev) 607 (let ((i 0) ev)
556 (while (< i (length macro)) 608 (while (< i (length macro))
557 (when (consp (setq ev (aref macro i))) 609 (when (consp (setq ev (aref macro i)))
558 (cond ((equal (cadadr ev) '(menu-bar)) 610 (cond ((equal (cadadr ev) '(menu-bar))
559 (setq macro (vconcat (subseq macro 0 i) 611 (setq macro (vconcat (edmacro-subseq macro 0 i)
560 (vector 'menu-bar (car ev)) 612 (vector 'menu-bar (car ev))
561 (subseq macro (1+ i)))) 613 (edmacro-subseq macro (1+ i))))
562 (incf i)) 614 (incf i))
563 ;; It would be nice to do pop-up menus, too, but not enough 615 ;; It would be nice to do pop-up menus, too, but not enough
564 ;; info is recorded in macros to make this possible. 616 ;; info is recorded in macros to make this possible.
@@ -647,7 +699,7 @@ doubt, use whitespace."
647 (eq (aref res 1) ?\() 699 (eq (aref res 1) ?\()
648 (eq (aref res (- (length res) 2)) ?\C-x) 700 (eq (aref res (- (length res) 2)) ?\C-x)
649 (eq (aref res (- (length res) 1)) ?\))) 701 (eq (aref res (- (length res) 1)) ?\)))
650 (setq res (subseq res 2 -2))) 702 (setq res (edmacro-subseq res 2 -2)))
651 (if (and (not need-vector) 703 (if (and (not need-vector)
652 (loop for ch across res 704 (loop for ch across res
653 always (and (integerp ch) 705 always (and (integerp ch)