Changeset 8461 for trunk/j/src/org/armedbear
- Timestamp:
- 02/04/05 04:28:47 (19 years ago)
- Location:
- trunk/j/src/org/armedbear
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/j/src/org/armedbear/j/LispAPI.java
r8198 r8461 2 2 * LispAPI.java 3 3 * 4 * Copyright (C) 2003-200 4Peter Graves5 * $Id: LispAPI.java,v 1.5 8 2004-11-28 15:44:25piso Exp $4 * Copyright (C) 2003-2005 Peter Graves 5 * $Id: LispAPI.java,v 1.59 2005-02-04 04:27:23 piso Exp $ 6 6 * 7 7 * This program is free software; you can redistribute it and/or … … 424 424 // ### make-mark 425 425 private static final Primitive MAKE_MARK = 426 new Primitive("make-mark", PACKAGE_J, true )426 new Primitive("make-mark", PACKAGE_J, true, "line offset") 427 427 { 428 428 public LispObject execute(LispObject first, LispObject second) … … 437 437 // ### mark-line 438 438 private static final Primitive MARK_LINE = 439 new Primitive("mark-line", PACKAGE_J, true )439 new Primitive("mark-line", PACKAGE_J, true, "mark") 440 440 { 441 441 public LispObject execute(LispObject arg) throws ConditionThrowable … … 447 447 // ### mark-charpos 448 448 private static final Primitive MARK_CHARPOS = 449 new Primitive("mark-charpos", PACKAGE_J, true )449 new Primitive("mark-charpos", PACKAGE_J, true, "mark") 450 450 { 451 451 public LispObject execute(LispObject arg) throws ConditionThrowable … … 562 562 // Move point right N characters (left if N is negative). 563 563 private static final Primitive FORWARD_CHAR = 564 new Primitive("forward-char", PACKAGE_J, true) 565 { 566 public LispObject execute() throws ConditionThrowable 567 { 568 return forwardChar(1); 569 } 570 public LispObject execute(LispObject arg) throws ConditionThrowable 571 { 572 return forwardChar(Fixnum.getValue(arg)); 564 new Primitive("forward-char", PACKAGE_J, true, "mark &optional count") 565 { 566 public LispObject execute(LispObject arg) throws ConditionThrowable 567 { 568 Position pos = checkMark(arg); 569 return forwardChar(pos, 1); 570 } 571 public LispObject execute(LispObject first, LispObject second) 572 throws ConditionThrowable 573 { 574 Position pos = checkMark(first); 575 return forwardChar(pos, Fixnum.getValue(second)); 573 576 } 574 577 }; 575 578 576 579 // ### backward-char 577 // Move point left N characters (right if Nis negative).580 // Move MARK left COUNT characters (right if COUNT is negative). 578 581 private static final Primitive BACKWARD_CHAR = 579 new Primitive("backward-char", PACKAGE_J, true) 580 { 581 public LispObject execute() throws ConditionThrowable 582 { 583 return forwardChar(-1); 584 } 585 public LispObject execute(LispObject arg) throws ConditionThrowable 586 { 587 return forwardChar(-Fixnum.getValue(arg)); 588 } 589 }; 590 591 private static final LispObject forwardChar(int n) throws ConditionThrowable 582 new Primitive("backward-char", PACKAGE_J, true, "mark &optional count") 583 { 584 public LispObject execute(LispObject arg) throws ConditionThrowable 585 { 586 Position pos = checkMark(arg); 587 return forwardChar(pos, -1); 588 } 589 public LispObject execute(LispObject first, LispObject second) 590 throws ConditionThrowable 591 { 592 Position pos = checkMark(first); 593 return forwardChar(pos, -Fixnum.getValue(second)); 594 } 595 }; 596 597 private static final LispObject forwardChar(Position pos, int n) 598 throws ConditionThrowable 592 599 { 593 600 if (n != 0) { 594 final Editor editor = Editor.currentEditor();595 Position pos = editor.getDot();596 601 if (pos != null) { 597 editor.addUndo(SimpleEdit.MOVE);598 602 if (n > 0) { 599 603 while (n-- > 0) { 600 604 if (!pos.next()) 601 return signal(new LispError(" reached end of buffer"));605 return signal(new LispError("Reached end of buffer.")); 602 606 } 603 607 } else { 604 Debug.assertTrue(n < 0);605 608 while (n++ < 0) { 606 609 if (!pos.prev()) 607 return signal(new LispError(" reached beginning of buffer"));610 return signal(new LispError("Reached beginning of buffer.")); 608 611 } 609 612 } 610 editor.moveCaretToDotCol();611 613 } 612 614 } … … 674 676 }; 675 677 676 // ### backward-up-list 678 // ### backward-up-list mark 677 679 private static final Primitive BACKWARD_UP_LIST = 678 new Primitive("backward-up-list", PACKAGE_J, true) 679 { 680 public LispObject execute() throws ConditionThrowable 681 { 682 LispMode.backwardUpList(); 683 return NIL; 684 } 685 }; 686 687 // ### looking-at pattern => generalized-boolean 680 new Primitive("backward-up-list", PACKAGE_J, true, "mark") 681 { 682 public LispObject execute(LispObject arg) throws ConditionThrowable 683 { 684 Position pos = checkMark(arg); 685 Position newPos = LispMode.findContainingSexp(pos); 686 if (newPos != null) 687 pos.moveTo(newPos); 688 return arg; 689 } 690 }; 691 692 // ### looking-at mark pattern => generalized-boolean 688 693 private static final Primitive LOOKING_AT = 689 new Primitive("looking-at", PACKAGE_J, true) 690 { 691 public LispObject execute(LispObject arg) throws ConditionThrowable 692 { 693 if (arg instanceof AbstractString) { 694 String pattern = arg.getStringValue(); 695 Editor editor = Editor.currentEditor(); 696 Position dot = editor.getDot(); 697 if (dot != null) { 698 if (dot.getLine().substring(dot.getOffset()).startsWith(pattern)) 699 return T; 700 } 694 new Primitive("looking-at", PACKAGE_J, true, "mark string") 695 { 696 public LispObject execute(LispObject first, LispObject second) 697 throws ConditionThrowable 698 { 699 Position pos = checkMark(first); 700 if (second instanceof AbstractString) { 701 String pattern = second.getStringValue(); 702 if (pos.getLine().substring(pos.getOffset()).startsWith(pattern)) 703 return T; 701 704 return NIL; 702 705 } 703 return signal(new TypeError( arg, Symbol.STRING));706 return signal(new TypeError(second, Symbol.STRING)); 704 707 } 705 708 }; … … 1020 1023 editor.unmark(); 1021 1024 return arg; 1025 } 1026 }; 1027 1028 // ### copy-mark mark => copy 1029 private static final Primitive COPY_MARK = 1030 new Primitive("copy-mark", PACKAGE_J, true, "mark") 1031 { 1032 public LispObject execute(LispObject arg) throws ConditionThrowable 1033 { 1034 Position pos = checkMark(arg); 1035 return new JavaObject(new Position(pos.getLine(), pos.getOffset())); 1036 } 1037 }; 1038 1039 // ### mark= mark1 mark2 => generalized-boolean 1040 private static final Primitive MARK_EQUAL = 1041 new Primitive("mark=", PACKAGE_J, true, "mark1 mark2") 1042 { 1043 public LispObject execute(LispObject first, LispObject second) 1044 throws ConditionThrowable 1045 { 1046 Position pos1 = checkMark(first); 1047 Position pos2 = checkMark(second); 1048 if (pos1.getLine() == pos2.getLine()) 1049 if (pos1.getOffset() == pos2.getOffset()) 1050 return T; 1051 return NIL; 1022 1052 } 1023 1053 }; -
trunk/j/src/org/armedbear/lisp/slime.lisp
r8440 r8461 2 2 ;;; 3 3 ;;; Copyright (C) 2004-2005 Peter Graves 4 ;;; $Id: slime.lisp,v 1.2 7 2005-02-01 03:38:22piso Exp $4 ;;; $Id: slime.lisp,v 1.28 2005-02-04 04:28:47 piso Exp $ 5 5 ;;; 6 6 ;;; This program is free software; you can redistribute it and/or … … 231 231 (values)) 232 232 233 (defun symbol-name-at-point () 234 (let ((string (line-chars (current-line))) 235 (point-charpos (mark-charpos (current-point))) 236 (begin 0) 237 end) 238 (when (= point-charpos (length string)) 239 (decf point-charpos)) 233 (defun symbol-name-at-mark (mark) 234 (let* ((string (line-chars (mark-line mark))) 235 (length (length string)) 236 (charpos (mark-charpos mark)) 237 (begin 0) 238 end) 239 (when (= charpos length) 240 (decf charpos)) 240 241 (loop 241 (aver (< point-charpos (length string)))242 (cond ((not (delimiter-p (schar string point-charpos)))242 (aver (< charpos length)) 243 (cond ((not (delimiter-p (schar string charpos))) 243 244 (return)) 244 ((zerop point-charpos)245 (return-from symbol-name-at- pointnil))245 ((zerop charpos) 246 (return-from symbol-name-at-mark nil)) 246 247 (t 247 (decf point-charpos))))248 (dotimes (i point-charpos)248 (decf charpos)))) 249 (dotimes (i charpos) 249 250 (let ((c (schar string i))) 250 251 (when (delimiter-p c) 251 252 (setf begin (1+ i))))) 252 (do ((i point-charpos (1+ i)))253 ((= i (length string)) (setf end i))253 (do ((i charpos (1+ i))) 254 ((= i length) (setf end i)) 254 255 (when (delimiter-p (schar string i)) 255 256 (setf end i) … … 257 258 (subseq string begin end))) 258 259 259 (defun enclosing-operator-names ( )260 (defun enclosing-operator-names (mark) 260 261 "Return the list of operator names of the forms containing point." 261 262 (let ((result ())) 262 (save-excursion 263 (loop 264 (let ((point1 (current-point)) 265 (point2 (progn (backward-up-list) (current-point)))) 266 (when (and (equal (mark-line point1) (mark-line point2)) 267 (eql (mark-charpos point1) (mark-charpos point2))) 268 (return))) 269 (unless (looking-at "(") 270 (return)) 271 (when (looking-at "(") 272 (forward-char) 273 (let ((name (symbol-name-at-point))) 274 (cond ((string-equal name "defun") 275 (return)) 276 ((null name) 277 (return)) 278 (t 279 (push name result)))) 280 (backward-up-list)))) 263 (loop 264 (let* ((mark1 (copy-mark mark)) 265 (mark2 (progn (backward-up-list mark) (copy-mark mark)))) 266 (when (mark= mark1 mark2) ; Can't go back any further. 267 (return))) 268 (unless (looking-at mark "(") 269 (return)) 270 (forward-char mark) 271 (let ((name (symbol-name-at-mark mark))) 272 (cond ((string-equal name "defun") 273 (return)) 274 ((null name) 275 (return)) 276 (t 277 (push name result)))) 278 (backward-up-list mark)) 281 279 (nreverse result))) 282 280 283 281 (defun slime-space () 284 282 (unwind-protect 285 (when (and (slime-connected-p)286 (not (slime-busy-p)))287 (let ((names (enclosing-operator-names)))288 (when names289 (slime-eval-async290 `(swank:arglist-for-echo-area (quote ,names))291 #'(lambda (message)292 (when (stringp message)293 (status (string-trim '(#\") message))))))))294 (insert #\space)))283 (when (and (slime-connected-p) 284 (not (slime-busy-p))) 285 (let ((names (enclosing-operator-names (current-point)))) 286 (when names 287 (slime-eval-async 288 `(swank:arglist-for-echo-area (quote ,names)) 289 #'(lambda (message) 290 (when (stringp message) 291 (status (string-trim '(#\") message)))))))) 292 (insert #\space))) 295 293 296 294 (defun find-buffer-package () … … 376 374 (return-from slime-edit-definition))) 377 375 (unless function-name 378 (setf function-name (string-upcase (symbol-name-at- point))))376 (setf function-name (string-upcase (symbol-name-at-mark (current-point))))) 379 377 (when function-name 380 378 (setf function-name (string function-name)) … … 448 446 (map-key-for-mode "Ctrl Alt I" "(slime:slime-complete-symbol)" "Lisp") 449 447 (map-key-for-mode "Space" "(slime:slime-space)" "Lisp Shell") 450 ;;(map-key-for-mode "Space" "(slime:slime-space)" "Lisp")448 (map-key-for-mode "Space" "(slime:slime-space)" "Lisp") 451 449 (map-key-for-mode "Alt ." "(slime:slime-edit-definition)" "Lisp Shell") 452 450 (map-key-for-mode "Alt ." "(slime:slime-edit-definition)" "Lisp")
Note: See TracChangeset
for help on using the changeset viewer.