slice of untabification master
authorNikodemus Siivola <nikodemus@random-state.net>
Sat, 23 Jun 2012 13:07:57 +0000 (16:07 +0300)
committerNikodemus Siivola <nikodemus@random-state.net>
Sat, 23 Jun 2012 13:07:57 +0000 (16:07 +0300)
command-functions.lisp

index 6aa4c55..8449b10 100644 (file)
@@ -1,4 +1,4 @@
-;;;; Copyright (c) 2003, 2004 Nikodemus Siivola, Julian Squires
+;;;; Copyright (c) 2003, 2004, 2012 Nikodemus Siivola, Julian Squires
 ;;;;
 ;;;; Permission is hereby granted, free of charge, to any person obtaining
 ;;;; a copy of this software and associated documentation files (the
     ;; Can't delegate to editor because of the SUBSEQ index calc.
     (unless (zerop point)
       (setf (get-string editor) (concat (subseq string 0 (1- point))
-                                       (subseq string point))
-           (get-point editor) (1- point)))))
+                                        (subseq string point))
+            (get-point editor) (1- point)))))
 
 (defun delete-char-forwards (chord editor)
   (declare (ignore chord))
   (with-editor-point-and-string ((point string) editor)
     (setf (get-string editor) (concat (subseq string 0 point)
-                                     (subseq string (min (1+ point) (length string)))))))
+                                      (subseq string (min (1+ point) (length string)))))))
 
 (defun delete-char-forwards-or-eof (chord editor)
   (if (equal "" (get-string editor))
@@ -73,8 +73,8 @@
   (with-editor-point-and-string ((point string) editor)
     (let ((i (editor-previous-word-start editor)))
       (setf (get-string editor) (concat (subseq string 0 i)
-                                       (subseq string point))
-           (get-point editor) i))))
+                                        (subseq string point))
+            (get-point editor) i))))
 
 (defun finish-input (chord editor)
   (declare (ignore chord editor))
 ;;; CASE CHANGES
 
 (flet ((frob-case (frob editor)
-        (with-editor-point-and-string ((point string) editor)
-          (let ((end (editor-next-word-end editor)))
-            (setf (get-string editor) (concat
-                                       (subseq string 0 point)
-                                       (funcall frob
-                                                (subseq string point end))
-                                       (subseq string end))
-                  (get-point editor) end)))))
+         (with-editor-point-and-string ((point string) editor)
+           (let ((end (editor-next-word-end editor)))
+             (setf (get-string editor) (concat
+                                        (subseq string 0 point)
+                                        (funcall frob
+                                                 (subseq string point end))
+                                        (subseq string end))
+                   (get-point editor) end)))))
 
   (defun upcase-word (chord editor)
     (declare (ignore chord))
 (defun %yank (editor)
   (aif (buffer-peek (editor-killring editor))
        (with-editor-point-and-string ((point string) editor)
-        (setf (get-string editor)
-              (concat (subseq string 0 (editor-yank editor))
-                      it
-                      (subseq string point))
-              (get-point editor) (+ (editor-yank editor) (length it))))
-       (beep editor)))
+         (setf (get-string editor)
+               (concat (subseq string 0 (editor-yank editor))
+                       it
+                       (subseq string point))
+               (get-point editor) (+ (editor-yank editor) (length it))))
+        (beep editor)))
 
 (defun yank (chord editor)
   (declare (ignore chord))
   (declare (ignore chord))
   (if (try-yank editor)
       (progn
-        (buffer-cycle (editor-killring editor))
-        (%yank editor))
+         (buffer-cycle (editor-killring editor))
+         (%yank editor))
       (beep editor)))
 
 (defun kill-to-eol (chord editor)
   (with-editor-point-and-string ((point string) editor)
     (buffer-push (subseq string 0 point) (editor-killring editor))
     (setf (get-string editor) (subseq string point)
-         (get-point editor) 0)))
+          (get-point editor) 0)))
 
 (defun copy-region (chord editor)
   (declare (ignore chord))
   (awhen (editor-mark editor)
      (with-editor-point-and-string ((point string) editor)
        (let ((start (min it point))
-            (end (max it point)))
-        (buffer-push (subseq string start end) (editor-killring editor))
-        (setf (editor-mark editor) nil)))))
+             (end (max it point)))
+         (buffer-push (subseq string start end) (editor-killring editor))
+         (setf (editor-mark editor) nil)))))
 
 (defun cut-region (chord editor)
   (declare (ignore chord))
   (awhen (editor-mark editor)
      (with-editor-point-and-string ((point string) editor)
        (let ((start (min it point))
-            (end (max it point)))
-       (copy-region t editor)
-       (setf (get-string editor) (concat (subseq string 0 start)
-                                         (subseq string end))
-             (get-point editor) start)))))
+             (end (max it point)))
+        (copy-region t editor)
+        (setf (get-string editor) (concat (subseq string 0 start)
+                                          (subseq string end))
+              (get-point editor) start)))))
 
 (defun set-mark (chord editor)
   (declare (ignore chord))
   (declare (ignore chord))
   (with-editor-point-and-string ((point string) editor)
     (let ((start (editor-sexp-start editor))
-         (end (min (1+ (editor-sexp-end editor)) (length string))))
+          (end (min (1+ (editor-sexp-end editor)) (length string))))
       (buffer-push (subseq string start end) (editor-killring editor))
       (setf (get-string editor) (concat (subseq string 0 start)
-                                       (subseq string end))
-           (get-point editor) start))))
+                                        (subseq string end))
+            (get-point editor) start))))
 
 (defun close-all-sexp (chord editor)
   (move-to-eol chord editor)
   (do ((string (get-string editor) (get-string editor)))
       ((not (find-open-paren string (length string))))
     (add-char (case (schar string (find-open-paren string (length string)))
-                   (#\( #\))
-                   (#\[ #\])
-                   (#\{ #\}))
-             editor)))
+                    (#\( #\))
+                    (#\[ #\])
+                    (#\{ #\}))
+              editor)))
 
 ;;; SIGNALS
 
 (defun help (chord editor)
   (declare (ignore chord))
   (let ((pairs nil)
-       (max-id 0)
-       (max-f 0))
+        (max-id 0)
+        (max-f 0))
     (maphash (lambda (id function)
-              (let ((f (string-downcase (symbol-name function))))
-                (push (list id f) pairs)
-                (setf max-id (max max-id (length id))
-                      max-f (max max-f (length f)))))
-            (editor-commands editor))
+               (let ((f (string-downcase (symbol-name function))))
+                 (push (list id f) pairs)
+                 (setf max-id (max max-id (length id))
+                       max-f (max max-f (length f)))))
+             (editor-commands editor))
     (print-in-columns editor
-                     (mapcar (lambda (pair)
-                                (destructuring-bind (id f) pair
-                                  (with-output-to-string (s)
-                                    (write-string id s)
-                                    (loop repeat (- (1+ max-id) (length id))
-                                          do (write-char #\Space s))
-                                    (write-string f s))))
-                             (nreverse pairs))
-                     :width (+ max-id max-f 2))))
+                      (mapcar (lambda (pair)
+                                 (destructuring-bind (id f) pair
+                                   (with-output-to-string (s)
+                                     (write-string id s)
+                                     (loop repeat (- (1+ max-id) (length id))
+                                           do (write-char #\Space s))
+                                     (write-string f s))))
+                              (nreverse pairs))
+                      :width (+ max-id max-f 2))))
 
 (defun unknown-command (chord editor)
   (newline editor)
   (declare (ignore chord))
   (multiple-value-bind (completions max-len) (editor-complete editor)
     (if completions
-       (if (not (cdr completions))
-           (editor-replace-word editor (car completions))
-           (print-in-columns editor completions :width (+ max-len 2)))
-       (beep editor))))
+        (if (not (cdr completions))
+            (editor-replace-word editor (car completions))
+            (print-in-columns editor completions :width (+ max-len 2)))
+        (beep editor))))
 
 (defun apropos-word (chord editor)
   (declare (ignore chord))
   (let* ((word (editor-word editor))
-        (apropi (apropos-list word)))
+         (apropi (apropos-list word)))
     (if (null apropi)
-       (beep editor)
-       (let* ((longest 0)
-              (strings (mapcar (lambda (symbol)
-                                 (declare (symbol symbol))
-                                 (let ((str (prin1-to-string symbol)))
-                                   (setf longest (max longest (length str)))
-                                   (string-downcase str)))
-                               apropi)))
-         (print-in-columns editor strings :width (+ longest 2))))))
+        (beep editor)
+        (let* ((longest 0)
+               (strings (mapcar (lambda (symbol)
+                                  (declare (symbol symbol))
+                                  (let ((str (prin1-to-string symbol)))
+                                    (setf longest (max longest (length str)))
+                                    (string-downcase str)))
+                                apropi)))
+          (print-in-columns editor strings :width (+ longest 2))))))
 
 (defun describe-word (chord editor)
   (declare (ignore chord))
   (print-in-lines editor
-                 (with-output-to-string (s)
-                   (describe (read-from-string (editor-word editor)) s))))
+                  (with-output-to-string (s)
+                    (describe (read-from-string (editor-word editor)) s))))
 
 (defun toggle-insert (chord editor)
   (declare (ignore chord))