Anonymous avatar Anonymous committed 3216a78

Basic infrastructure for inserting function types. Issue #14.

Signed-off-by: Austin Seipp <aseipp@pobox.com>;

Comments (0)

Files changed (1)

 (require 'easymenu)
 (require 'font-lock)
 (require 'generic-x)
+(require 'thingatpt)
 
 ;;; -- Customization variables -------------------------------------------------
 
 (defvar cryptol-mode-map
   (let ((map (make-sparse-keymap)))
     (define-key map (kbd "C-c C-l") 'cryptol-repl)
+    (define-key map (kbd "M-t") 'cryptol-insert-type-sig)
     map)
   "Keymap for `cryptol-mode'.")
 
   "Process output from cryptol, removing stupid libedit noise on Linux.
   TODO: Elaborate further on this stupidity."
   (if (not (eq nil args))
-      (let ((cryptol-output (process-lines cryptol-command "-v")))
+      (let ((cryptol-output (apply 'process-lines (append (list cryptol-command) args))))
 	(if (not (eq nil (string-prefix-p "No entry for terminal type "
 					  (car cryptol-output))))
 	    (nthcdr 2 cryptol-output)
       (setq *cryptol-version* cryptol-version)
       *cryptol-version*)))
 
+(defun get-type-sig-for-symbol (sym)
+  "Get the type signature for a symbol."
+  (interactive)
+  (let ((out (process-lines-cryptol "-qns" (buffer-file-name) "-c" (concat ":type " sym))))
+    (mapconcat 'identity out " ")))
+
 ;;;###autoload
 (defun cryptol-backends ()
   "Show the backends supported by the `cryptol-command'."
     (message (concat "cryptol-mode v" cryptol-mode-version
 		     ", using Cryptol version " cryptol-ver-out))))
 
+(defun cryptol-insert-type-sig ()
+  "Insert a type signature for the symbol under point."
+  (interactive)
+  (let ((sym (thing-at-point 'symbol)))
+    (message (get-type-sig-for-symbol sym)))
+  )
+
 ;;; -- imenu support -----------------------------------------------------------
 
 (easy-menu-define cryptol-mode-menu cryptol-mode-map
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.