Changeset 12281


Ignore:
Timestamp:
Jun 23, 2009, 5:44:21 PM (10 years ago)
Author:
mikel
Message:

Ticket #471: implemented selection-collapsing without movement for all the forward and backward movement commands

Location:
trunk/source/cocoa-ide/hemlock/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/cocoa-ide/hemlock/src/command.lisp

    r12280 r12281  
    1717;;; utility for collapsing selections from movement commands
    1818;;; returns a true value if a selection was collapsed, false otherwise
    19 (defun collapse-if-selection (&key (direction :end))
    20   (assert (memq direction '(:start :end))()
    21           "collapse-if-selection requires a :direction argument equal to either :start or :end")
     19(defun collapse-if-selection (&key (direction :forward))
     20  (assert (memq direction '(:backward :forward))()
     21          "collapse-if-selection requires a :direction argument equal to either :backward or :forward")
    2222  (if (hi::%buffer-current-region-p hi::*current-buffer*)
    2323      (multiple-value-bind (start end)(region-bounds (current-region nil nil))
    24         (let ((d (ecase direction ((:end) end)((:start) start))))
     24        (let ((d (ecase direction ((:forward) end)((:backward) start))))
    2525          (setf (buffer-point hi::*current-buffer*) d)
    2626          (setf (hi::buffer-region-active hi::*current-buffer*) nil)
     
    8080   go backwards."
    8181    "Move the point of the current buffer forward p characters, collapsing the selection."
    82   (or (collapse-if-selection :direction :end)
     82  (or (collapse-if-selection :direction :forward)
    8383      (let* ((p (cond
    8484                  (p p)
     
    119119  With prefix argument move that many characters backward."
    120120    "Move the point p characters backward, collapsing the selection."
    121   (or (collapse-if-selection :direction :start)
     121  (or (collapse-if-selection :direction :backward)
    122122      (forward-character-command (if p (- p) -1))))
    123123
     
    218218  With prefix argument, moves the point forward over that many words."
    219219    "Moves the point forward p words, collapsing the selection."
    220   (or (collapse-if-selection :direction :end)
     220  (or (collapse-if-selection :direction :forward)
    221221      (let* ((point (current-point-collapsing-selection)))
    222222        (cond ((word-offset point (or p 1)))
     
    245245  With prefix argument, moves the point back over that many words."
    246246  "Moves the point backward p words."
    247   (or (collapse-if-selection :direction :start)
     247  (or (collapse-if-selection :direction :backward)
    248248   (forward-word-command (- (or p 1)))))
    249249
  • trunk/source/cocoa-ide/hemlock/src/lispmode.lisp

    r12122 r12281  
    13071307  With argument, skips the next p lists."
    13081308  "Skip over the next Lisp list, collapsing the selection."
    1309   (let ((point (current-point-collapsing-selection))
    1310         (count (or p 1)))
    1311     (pre-command-parse-check point)
    1312     (unless (list-offset point count) (editor-error))))
     1309  (or (collapse-if-selection :direction :forward)
     1310      (let ((point (current-point-collapsing-selection))
     1311            (count (or p 1)))
     1312        (pre-command-parse-check point)
     1313        (unless (list-offset point count) (editor-error)))))
    13131314
    13141315(defcommand "Select Forward List" (p)
     
    13251326  With argument, skips the previous p lists."
    13261327  "Skip over the previous Lisp list, collapsing the selection."
    1327   (let ((point (current-point-collapsing-selection))
     1328  (or (collapse-if-selection :direction :backward)
     1329   (let ((point (current-point-collapsing-selection))
    13281330        (count (- (or p 1))))
    13291331    (pre-command-parse-check point)
    1330     (unless (list-offset point count) (editor-error))))
     1332    (unless (list-offset point count) (editor-error)))))
    13311333
    13321334(defcommand "Select Backward List" (p)
     
    13401342
    13411343(defcommand "Forward Form" (p)
    1342   "Skip over the next Form, collapsing the selection.
     1344    "Skip over the next Form, collapsing the selection.
    13431345  With argument, skips the next p Forms."
    1344   "Skip over the next Form, collapsing the selection."
    1345   (let ((point (current-point-collapsing-selection))
    1346         (count (or p 1)))
    1347     (pre-command-parse-check point)
    1348     (unless (form-offset point count) (editor-error))))
     1346    "Skip over the next Form, collapsing the selection."
     1347  (or (collapse-if-selection :direction :forward)
     1348      (let ((point (current-point-collapsing-selection))
     1349            (count (or p 1)))
     1350        (pre-command-parse-check point)
     1351        (unless (form-offset point count) (editor-error)))))
    13491352
    13501353(defcommand "Select Forward Form" (p)
     
    13581361
    13591362(defcommand "Backward Form" (p)
    1360   "Skip over the previous Form, collapsing the selection.
     1363    "Skip over the previous Form, collapsing the selection.
    13611364  With argument, skips the previous p Forms."
    1362   "Skip over the previous Form, collaspsing the selection."
    1363   (let ((point (current-point-collapsing-selection))
    1364         (count (- (or p 1))))
    1365     (pre-command-parse-check point)
    1366     (unless (form-offset point count) (editor-error))))
     1365    "Skip over the previous Form, collaspsing the selection."
     1366  (or (collapse-if-selection :direction :backward)
     1367      (let ((point (current-point-collapsing-selection))
     1368            (count (- (or p 1))))
     1369        (pre-command-parse-check point)
     1370        (unless (form-offset point count) (editor-error)))))
    13671371
    13681372(defcommand "Select Backward Form" (p)
     
    15811585
    15821586(defcommand "Forward Up List" (p)
    1583   "Move forward past a one containing )."
    1584   "Move forward past a one containing )."
    1585   (let ((point (current-point-collapsing-selection))
    1586         (count (or p 1)))
    1587     (pre-command-parse-check point)
    1588     (if (minusp count)
    1589         (backward-up-list-command (- count))
    1590         (with-mark ((m point))
    1591           (dotimes (i count (move-mark point m))
    1592             (unless (forward-up-list m) (editor-error)))))))
    1593 
     1587    "Move forward past a one containing )."
     1588    "Move forward past a one containing )."
     1589  (or (collapse-if-selection :direction :forward)
     1590      (let ((point (current-point-collapsing-selection))
     1591            (count (or p 1)))
     1592        (pre-command-parse-check point)
     1593        (if (minusp count)
     1594            (backward-up-list-command (- count))
     1595            (with-mark ((m point))
     1596              (dotimes (i count (move-mark point m))
     1597                (unless (forward-up-list m) (editor-error))))))))
    15941598
    15951599(defcommand "Backward Up List" (p)
    1596   "Move backward past a one containing (."
    1597   "Move backward past a one containing (."
    1598   (let ((point (current-point-collapsing-selection))
    1599         (count (or p 1)))
    1600     (pre-command-parse-check point)
    1601     (if (minusp count)
    1602         (forward-up-list-command (- count))
    1603         (with-mark ((m point))
    1604           (dotimes (i count (move-mark point m))
    1605             (unless (backward-up-list m) (editor-error)))))))
     1600    "Move backward past a one containing (."
     1601    "Move backward past a one containing (."
     1602  (or (collapse-if-selection :direction :backward)
     1603      (let ((point (current-point-collapsing-selection))
     1604            (count (or p 1)))
     1605        (pre-command-parse-check point)
     1606        (if (minusp count)
     1607            (forward-up-list-command (- count))
     1608            (with-mark ((m point))
     1609              (dotimes (i count (move-mark point m))
     1610                (unless (backward-up-list m) (editor-error))))))))
    16061611
    16071612
  • trunk/source/cocoa-ide/hemlock/src/text.lisp

    r6663 r12281  
    3434
    3535(defcommand "Forward Paragraph" (p)
    36   "moves point to the end of the current (next) paragraph."
    37   "moves point to the end of the current (next) paragraph."
    38   (let ((point (current-point)))
    39     (unless (paragraph-offset point (or p 1))
    40       (buffer-end point)
    41       (editor-error))))
     36    "moves point to the end of the current (next) paragraph."
     37    "moves point to the end of the current (next) paragraph."
     38  (or (collapse-if-selection :direction :forward)
     39      (let ((point (current-point)))
     40        (unless (paragraph-offset point (or p 1))
     41          (buffer-end point)
     42          (editor-error)))))
    4243
    4344(defcommand "Backward Paragraph" (p)
    44   "moves point to the start of the current (previous) paragraph."
    45   "moves point to the start of the current (previous) paragraph."
    46   (let ((point (current-point)))
    47     (unless (paragraph-offset point (- (or p 1)))
    48       (buffer-start point)
    49       (editor-error))))
     45    "moves point to the start of the current (previous) paragraph."
     46    "moves point to the start of the current (previous) paragraph."
     47  (or (collapse-if-selection :direction :backward)
     48      (let ((point (current-point)))
     49        (unless (paragraph-offset point (- (or p 1)))
     50          (buffer-start point)
     51          (editor-error)))))
    5052
    5153(defcommand "Mark Paragraph" (p)
     
    244246
    245247(defcommand "Forward Sentence" (p)
    246   "Moves forward one sentence or the specified number.
     248    "Moves forward one sentence or the specified number.
    247249   A sentence terminates with a .,?, or ! followed by any number of closing
    248250   delimiters (such as \",',),],>,|) which are followed by either two
    249251   spaces or a newline."
    250   "Moves forward one sentence or the specified number."
    251   (unless (sentence-offset (current-point) (or p 1))
    252     (editor-error)))
     252    "Moves forward one sentence or the specified number."
     253  (or (collapse-if-selection :direction :forward)
     254      (unless (sentence-offset (current-point) (or p 1))
     255        (editor-error))))
    253256
    254257
    255258
    256259(defcommand "Backward Sentence" (p)
    257   "Moves backward one sentence or the specified number.
     260    "Moves backward one sentence or the specified number.
    258261   A sentence terminates with a .,?, or ! followed by any number of closing
    259262   delimiters (such as \",',),],>,|) which are followed by either two
    260263   spaces or a newline."
    261   "Moves backward one sentence or the specified number."
    262    (unless (sentence-offset (current-point) (- (or p 1)))
    263     (editor-error)))
     264    "Moves backward one sentence or the specified number."
     265  (or (collapse-if-selection :direction :forward)
     266      (unless (sentence-offset (current-point) (- (or p 1)))
     267        (editor-error))))
    264268
    265269
Note: See TracChangeset for help on using the changeset viewer.