]> code.delx.au - gnu-emacs-elpa/blobdiff - packages/sotlisp/sotlisp.el
Fix some quoting problems in doc strings
[gnu-emacs-elpa] / packages / sotlisp / sotlisp.el
index 5e3dcb413cdde27b23c1d027fd3cbe2a2a4e5a8d..2ceb382723ed5eb243bcbfa54c32d0e1878a4a85 100644 (file)
@@ -2,11 +2,11 @@
 
 ;; Copyright (C) 2014, 2015 Free Software Foundation, Inc.
 
-;; Author: Artur Malabarba  <bruce.connor.am@>
+;; Author: Artur Malabarba <emacs@endlessparentheses.com>
 ;; URL: https://github.com/Malabarba/speed-of-thought-lisp
 ;; Keywords: convenience, lisp
 ;; Package-Requires: ((emacs "24.1"))
-;; Version: 1.3
+;; Version: 1.5.2
 
 ;; This program is free software; you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
 ;;
 ;; A large number of abbrevs which expand function
 ;; initials to their name.  A few examples:
-;; 
+;;
 ;; - wcb -> with-current-buffer
 ;; - i -> insert
 ;; - r -> require '
 ;; - a -> and
-;; 
+;;
 ;; However, these are defined in a way such that they ONLY expand in a
 ;; place where you would use a function, so hitting SPC after "(r"
 ;; expands to "(require '", but hitting SPC after "(delete-region r"
 ;; thought-flow" way of writing.  The bindings are as follows, I
 ;; understand these don't fully adhere to conventions, and I'd
 ;; appreciate suggestions on better bindings.
-;; 
+;;
 ;; - M-RET :: Break line, and insert "()" with point in the middle.
 ;; - C-RET :: Do `forward-up-list', then do M-RET.
-;; 
+;;
 ;; Hitting RET followed by a `(' was one of the most common key sequences
 ;; for me while writing elisp, so giving it a quick-to-hit key was a
 ;; significant improvement.
-;; 
+;;
 ;; - C-c f :: Find function under point.  If it is not defined, create a
 ;; definition for it below the current function and leave point inside.
 ;; - C-c v :: Same, but for variable.
-;; 
+;;
 ;; With these commands, you just write your code as you think of it.  Once
 ;; you hit a "stop-point" of sorts in your tought flow, you hit `C-c f/v`
 ;; on any undefined functions/variables, write their definitions, and hit
 ;; `C-u C-SPC` to go back to the main function.
-;; 
+;;
 ;;; Small Example
 ;;
 ;; With the above (assuming you use something like paredit or
 ;; electric-pair-mode), if you write:
 ;;
 ;;   ( w t b M-RET i SPC text
-;; 
+;;
 ;; You get
-;; 
+;;
 ;;   (with-temp-buffer (insert text))
 
-\f
 ;;; Code:
 
 ;;; Predicates
   "Non-nil if point is at the start of a sexp.
 Specially, avoids matching inside argument lists."
   (and (eq (char-before) ?\()
-       (not (sotlisp--looking-back "(\\(defun\\s-+.*\\|lambda\\s-+\\)("))
+       (not (sotlisp--looking-back "(\\(defun\\s-+.*\\|\\(lambda\\|dolist\\|dotimes\\)\\s-+\\)("))
+       (save-excursion
+         (forward-char -1)
+         (condition-case er
+             (progn
+               (backward-up-list)
+               (forward-sexp -1)
+               (not
+                (looking-at-p (rx (* (or (syntax word) (syntax symbol) "-"))
+                                  "let" symbol-end))))
+           (error t)))
        (not (string-match (rx (syntax symbol)) (string last-command-event)))))
 
 (defun sotlisp--function-quote-p ()
@@ -253,10 +262,13 @@ The space char is not included.  Any \"$\" are also removed."
     ("dfv" . "defvar $ t\n  \"\"")
     ("dk" . "define-key ")
     ("dl" . "dolist (it $)")
+    ("dt" . "dotimes (it $)")
     ("dmp" . "derived-mode-p '")
+    ("dm" . "defmacro $ ()\n  \"\"\n  ")
     ("dr" . "delete-region ")
     ("dv" . "defvar $ t\n  \"\"")
     ("e" . "error \"$\"")
+    ("ef" . "executable-find ")
     ("efn" . "expand-file-name ")
     ("eol" . "end-of-line")
     ("f" . "format \"$\"")
@@ -268,6 +280,7 @@ The space char is not included.  Any \"$\" are also removed."
     ("fp" . "functionp ")
     ("frp" . "file-readable-p ")
     ("fs" . "forward-sexp 1")
+    ("fu" . "funcall ")
     ("fw" . "forward-word 1")
     ("g" . "goto-char ")
     ("gc" . "goto-char ")
@@ -296,11 +309,14 @@ The space char is not included.  Any \"$\" are also removed."
     ("lp" . "listp ")
     ("m" . "message \"$%s\"")
     ("mb" . "match-beginning 0")
+    ("mc" . "mapcar ")
+    ("mct" . "mapconcat ")
     ("me" . "match-end 0")
     ("ms" . "match-string 0")
     ("msn" . "match-string-no-properties 0")
     ("msnp" . "match-string-no-properties 0")
     ("msp" . "match-string-no-properties 0")
+    ("mt" . "mapconcat ")
     ("n" . "not ")
     ("nai" . "newline-and-indent$")
     ("nl" . "forward-line 1")
@@ -312,6 +328,7 @@ The space char is not included.  Any \"$\" are also removed."
     ("pa" . "point-max$")
     ("pg" . "plist-get ")
     ("pi" . "point-min$")
+    ("pz" . "propertize ")
     ("r" . "require '")
     ("ra" . "use-region-p$")
     ("rap" . "use-region-p$")
@@ -324,8 +341,8 @@ The space char is not included.  Any \"$\" are also removed."
     ("rris" . "replace-regexp-in-string ")
     ("rrs" . "replace-regexp-in-string ")
     ("rs" . "while (search-forward $ nil t)\n(replace-match \"\") nil t)")
-    ("rsb" . "re-search-backward $ nil 'noerror")
-    ("rsf" . "re-search-forward $ nil 'noerror")
+    ("rsb" . "re-search-backward \"$\" nil 'noerror")
+    ("rsf" . "re-search-forward \"$\" nil 'noerror")
     ("s" . "setq ")
     ("sb" . "search-backward $ nil 'noerror")
     ("sbr" . "search-backward-regexp $ nil 'noerror")
@@ -335,7 +352,7 @@ The space char is not included.  Any \"$\" are also removed."
     ("sf" . "search-forward $ nil 'noerror")
     ("sfr" . "search-forward-regexp $ nil 'noerror")
     ("sic" . "self-insert-command")
-    ("sl" . "string<")
+    ("sl" . "setq-local ")
     ("sm" . "string-match \"$\"")
     ("smd" . "save-match-data")
     ("sn" . "symbol-name ")
@@ -349,6 +366,8 @@ The space char is not included.  Any \"$\" are also removed."
     ("sw" . "selected-window$")
     ("syp" . "symbolp ")
     ("tap" . "thing-at-point 'symbol")
+    ("tf" . "thread-first ")
+    ("tl" . "thread-last ")
     ("u" . "unless ")
     ("ul" . "up-list")
     ("up" . "unwind-protect\n(progn $)")
@@ -360,6 +379,7 @@ The space char is not included.  Any \"$\" are also removed."
     ("wl" . "when-let (($))")
     ("we" . "window-end")
     ("ws" . "window-start")
+    ("wsw" . "with-selected-window ")
     ("wtb" . "with-temp-buffer")
     ("wtf" . "with-temp-file ")
     )
@@ -368,14 +388,14 @@ The space char is not included.  Any \"$\" are also removed."
 (defun sotlisp-define-function-abbrev (name expansion)
   "Define a function abbrev expanding NAME to EXPANSION.
 This abbrev will only be expanded in places where a function name is
-sensible.  Roughly, this is right after a `(' or a `#''.
+sensible.  Roughly, this is right after a `(' or a `#\\=''.
 
 If EXPANSION is any string, it doesn't have to be the just the
 name of a function.  In particular:
   - if it contains a `$', this char will not be inserted and
     point will be moved to its position after expansion.
   - if it contains a space, only a substring of it up to the
-first space is inserted when expanding after a `#'' (this is done
+first space is inserted when expanding after a `#\\='' (this is done
 by defining two different abbrevs).
 
 For instance, if one defines
@@ -384,7 +404,7 @@ For instance, if one defines
 then triggering `expand-abbrev' after \"d\" expands in the
 following way:
    (d    => (delete-char 1
-   #'d   => #'delete-char"
+   #\\='d   => #\\='delete-char"
   (define-abbrev emacs-lisp-mode-abbrev-table
     name t #'sotlisp--expand-function
     ;; Don't override user abbrevs
@@ -445,11 +465,14 @@ If `speed-of-thought-mode' is already on, call ON."
   nil nil " SoT"
   `(([M-return] . sotlisp-newline-and-parentheses)
     ([C-return] . sotlisp-downlist-newline-and-parentheses)
-    (,(kbd "C-M-;") . ,(if (boundp 'comment-or-uncomment-sexp)
+    (,(kbd "C-M-;") . ,(if (fboundp 'comment-or-uncomment-sexp)
                            #'comment-or-uncomment-sexp
                          #'sotlisp-comment-or-uncomment-sexp))
     ("\C-cf"    . sotlisp-find-or-define-function)
-    ("\C-cv"    . sotlisp-find-or-define-variable)))
+    ("\C-cv"    . sotlisp-find-or-define-variable))
+  (if sotlisp-mode
+      (abbrev-mode 1)
+    (kill-local-variable 'abbrev-mode)))
 
 (defun sotlisp-turn-on-everywhere ()
   "Call-once function to turn on sotlisp everywhere.
@@ -514,8 +537,9 @@ removes hooks and abbrevs."
   "`push-mark' and move above this defun."
   (push-mark)
   (beginning-of-defun)
-  (when (looking-back "^;;;###autoload\\s-*\n")
-    (forward-line -1)))
+  (forward-line -1)
+  (unless (looking-at "^;;;###autoload\\s-*\n")
+    (forward-line 1)))
 
 (defun sotlisp--function-at-point ()
   "Return name of `function-called-at-point'."
@@ -596,6 +620,7 @@ With a prefix argument, defines a `defvar' instead of a `defcustom'."
   "Uncomment a sexp around point."
   (interactive "P")
   (let* ((initial-point (point-marker))
+         (inhibit-field-text-motion t)
          (p)
          (end (save-excursion
                 (when (elt (syntax-ppss) 4)
@@ -607,26 +632,32 @@ With a prefix argument, defines a `defvar' instead of a `defcustom'."
                 (point-marker)))
          (beg (save-excursion
                 (forward-line 0)
-                (while (= end (save-excursion
-                                (comment-forward (point-max))
-                                (point)))
+                (while (and (not (bobp))
+                            (= end (save-excursion
+                                     (comment-forward (point-max))
+                                     (point))))
                   (forward-line -1))
                 (goto-char (line-end-position))
                 (re-search-backward comment-start-skip
                                     (line-beginning-position)
                                     t)
-                (while (looking-at-p comment-start-skip)
-                  (forward-char -1))
+                (ignore-errors
+                  (while (looking-at comment-start-skip)
+                    (forward-char -1))
+                  (unless (looking-at "[\n\r[:blank]]")
+                    (forward-char 1)))
                 (point-marker))))
     (unless (= beg end)
       (uncomment-region beg end)
       (goto-char p)
       ;; Indentify the "top-level" sexp inside the comment.
-      (while (and (ignore-errors (backward-up-list) t)
-                  (>= (point) beg))
-        (skip-chars-backward (rx (syntax expression-prefix)))
-        (setq p (point-marker)))
-      ;; Re-comment everything before it. 
+      (ignore-errors
+        (while (>= (point) beg)
+          (backward-prefix-chars)
+          (skip-chars-backward "\r\n[:blank:]")
+          (setq p (point-marker))
+          (backward-up-list)))
+      ;; Re-comment everything before it.
       (ignore-errors
         (comment-region beg p))
       ;; And everything after it.
@@ -639,7 +670,7 @@ With a prefix argument, defines a `defvar' instead of a `defcustom'."
         ;; If this is a closing delimiter, pull it up.
         (goto-char end)
         (skip-chars-forward "\r\n[:blank:]")
-        (when (= 5 (car (syntax-after (point))))
+        (when (eq 5 (car (syntax-after (point))))
           (delete-indentation))))
     ;; Without a prefix, it's more useful to leave point where
     ;; it was.