From b3cad6b22ce3f9fb00baf8c3fdd2e815ac8e9742 Mon Sep 17 00:00:00 2001 From: Philippe Brochard Date: Wed, 27 Jun 2012 22:58:50 +0200 Subject: [PATCH] src/clfswm-util.lisp (eval-from-query-string): Add completion for eval for query string. --- ChangeLog | 5 +++++ src/clfswm-util.lisp | 46 ++++++++++++++++++++++++++++------------------ src/config.lisp | 2 +- src/tools.lisp | 20 +++++++++++++++++++- 4 files changed, 53 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index c0af3cb..adee0cc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2012-06-27 Philippe Brochard + + * src/clfswm-util.lisp (eval-from-query-string): Add completion + for eval for query string. + 2012-06-26 Philippe Brochard * src/clfswm-query.lisp: Add completion for shell commands. diff --git a/src/clfswm-util.lisp b/src/clfswm-util.lisp index 0799231..9feb0b3 100644 --- a/src/clfswm-util.lisp +++ b/src/clfswm-util.lisp @@ -540,24 +540,34 @@ -(defun eval-from-query-string () - "Eval a lisp form from the query input" - (let ((form (query-string (format nil "Eval Lisp - ~A" (package-name *package*)))) - (result nil)) - (when (and form (not (equal form ""))) - (let ((printed-result - (with-output-to-string (*standard-output*) - (setf result (handler-case - (loop for i in (multiple-value-list - (eval (read-from-string form))) - collect (format nil "~S" i)) - (error (condition) - (format nil "~A" condition))))))) - (info-mode (expand-newline (append (ensure-list (format nil "> ~A" form)) - (ensure-list printed-result) - (ensure-list result))) - :width (- (xlib:screen-width *screen*) 2)) - (eval-from-query-string))))) +(let ((all-symbols (collect-all-symbols))) + (defun eval-from-query-string () + "Eval a lisp form from the query input" + (let ((form (query-string (format nil "Eval Lisp <~A> " (package-name *package*)) + "" all-symbols)) + (result nil)) + (when (and form (not (equal form ""))) + (let ((printed-result + (with-output-to-string (*standard-output*) + (setf result (handler-case + (loop for i in (multiple-value-list + (eval (read-from-string form))) + collect (format nil "~S" i)) + (error (condition) + (format nil "~A" condition))))))) + (let ((ret (info-mode (expand-newline (append (ensure-list (format nil "> ~A" form)) + (ensure-list printed-result) + (ensure-list result))) + :width (- (xlib:screen-width *screen*) 2)))) + (when (or (search "defparameter" form :test #'string-equal) + (search "defvar" form :test #'string-equal)) + (let ((elem (split-string form))) + (pushnew (string-downcase (if (string= (first elem) "(") (third elem) (second elem))) + all-symbols :test #'string=))) + (when (search "in-package" form :test #'string-equal) + (setf all-symbols (collect-all-symbols))) + (when ret + (eval-from-query-string)))))))) diff --git a/src/config.lisp b/src/config.lisp index f031790..e651c4b 100644 --- a/src/config.lisp +++ b/src/config.lisp @@ -259,7 +259,7 @@ on the root window in the main mode with the mouse") 'Query-string "Query string window background transparency") (defconfig *query-max-complet-length* 100 'Query-string "Query maximum length of completion list") -(defconfig *query-min-complet-char* 1 +(defconfig *query-min-complet-char* 2 'Query-string "Query minimum input length for completion") diff --git a/src/tools.lisp b/src/tools.lisp index 3759afd..d7e6346 100644 --- a/src/tools.lisp +++ b/src/tools.lisp @@ -56,6 +56,7 @@ :dbgnl :dbgc :distance + :collect-all-symbols :with-all-internal-symbols :export-all-functions :export-all-variables :export-all-functions-and-variables @@ -383,6 +384,19 @@ Return the result of the last hook" ;;; Symbols tools +(defun collect-all-symbols (&optional package) + (format t "Collecting all symbols for completion...") + (let (all-symbols) + (do-symbols (symbol (or package *package*)) + (pushnew (string-downcase (symbol-name symbol)) all-symbols :test #'string=)) + (do-symbols (symbol :keyword) + (pushnew (concatenate 'string ":" (string-downcase (symbol-name symbol))) + all-symbols :test #'string=)) + (format t " Done.~%") + all-symbols)) + + + (defmacro with-all-internal-symbols ((var package) &body body) "Bind symbol to all internal symbols in package" `(do-symbols (,var ,package) @@ -525,7 +539,11 @@ Return the result of the last hook" (eq char #\-) (eq char #\_) (eq char #\.) - (eq char #\+))) + (eq char #\+) + (eq char #\=) + (eq char #\*) + (eq char #\:) + (eq char #\%))) (defun append-newline-space (string) -- 2.11.4.GIT