mirror of
https://github.com/stumpwm/stumpwm-contrib.git
synced 2026-09-10 07:26:25 -04:00
Merge pull request #294 from pdubq/surfraw-refactor
surfraw: refactor and add autocomplete
This commit is contained in:
commit
e12303a28d
|
|
@ -5,12 +5,14 @@
|
|||
(dolist (elvi (surfraw-elvis-list))
|
||||
(let ((key (first elvi))
|
||||
(description (second elvi)))
|
||||
(push `(defcommand ,(intern (concat "sr-" key)) (search)
|
||||
(push `(defcommand ,(format-symbol t "~@:(sr-~a~)" key) (search)
|
||||
((:string ,(concat description ": ")))
|
||||
,description
|
||||
(surfraw ,key search))
|
||||
commands)
|
||||
(push `(defcommand ,(intern (concat "sr-sel-" key)) () ()
|
||||
(push `(defcommand ,(format-symbol t "~@:(sr-sel-~a~)" key) () ()
|
||||
(surfraw ,key (get-x-selection)))
|
||||
commands)))
|
||||
(cons 'progn (reverse commands))))
|
||||
|
||||
(auto-define-surfraw-commands-from-elvis-list)
|
||||
|
|
@ -1,5 +1,11 @@
|
|||
;;;; package.lisp
|
||||
|
||||
(defpackage #:surfraw
|
||||
(:use #:cl :stumpwm))
|
||||
|
||||
(:use #:cl #:stumpwm)
|
||||
(:import-from #:uiop
|
||||
#:run-program
|
||||
#:file-exists-p
|
||||
#:read-file-string)
|
||||
(:import-from #:alexandria
|
||||
#:if-let
|
||||
#:format-symbol))
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
:description "Integrates surfraw with stumpwm."
|
||||
:author "Ivy Foster"
|
||||
:license "GPLv3"
|
||||
:depends-on (#:stumpwm)
|
||||
:depends-on (#:stumpwm #:alexandria #:uiop)
|
||||
:components ((:file "package")
|
||||
(:file "macros" :depends-on ("package"))
|
||||
(:file "surfraw" :depends-on ("macros"))))
|
||||
(:file "surfraw")
|
||||
(:file "auto-commands")))
|
||||
|
|
|
|||
|
|
@ -14,24 +14,27 @@
|
|||
|
||||
;;; Code:
|
||||
|
||||
(defun split-by-- (str)
|
||||
(let ((pos (position #\- str :start (1+ (position #\- str)))))
|
||||
(list (subseq str 0 (1- pos))
|
||||
(subseq str (1+ pos)))))
|
||||
|
||||
(defun surfraw-elvis-list ()
|
||||
(mapcar (lambda (x)
|
||||
(mapcar (lambda (x) (string-trim '(#\Space #\Tab #\Newline) x))
|
||||
(split-by-- x)))
|
||||
(remove-if-not #'(lambda (string) (search "--" string))
|
||||
(split-string (run-shell-command "surfraw -elvi" :collect-output-p)
|
||||
'(#\Newline)))))
|
||||
(macrolet ((trim (str) `(string-trim '(#\Space #\Tab) ,str)))
|
||||
(loop :for line :in (run-program '("surfraw" "-elvi") :output :lines)
|
||||
:for pos = (search "--" line)
|
||||
:when pos
|
||||
:collect (list (trim (subseq line 0 pos))
|
||||
(trim (subseq line (+ pos 2)))))))
|
||||
|
||||
(auto-define-surfraw-commands-from-elvis-list)
|
||||
;;; Regular surfraw commands
|
||||
|
||||
(define-stumpwm-type :surfraw-elvi (input prompt)
|
||||
(let ((elvis (mapcar 'car (surfraw-elvis-list))))
|
||||
(or (find (or (argument-pop input)
|
||||
(completing-read (current-screen) prompt elvis :require-match t)
|
||||
(throw 'error "Abort"))
|
||||
elvis :test 'string=)
|
||||
(throw 'error "Such elvi doesn't exist"))))
|
||||
|
||||
(defcommand surfraw (engine search)
|
||||
((:string "What engine? ") (:string "Search for what? "))
|
||||
((:surfraw-elvi "What engine? ")
|
||||
(:string "Search for what? "))
|
||||
"Use SURFRAW to surf the net; reclaim heathen lands."
|
||||
(check-type engine string)
|
||||
(check-type search string)
|
||||
|
|
@ -39,19 +42,15 @@
|
|||
|
||||
;;; Bookmarks
|
||||
|
||||
(defun display-file (file)
|
||||
"Display a file in the message area."
|
||||
(if (probe-file file)
|
||||
(run-shell-command (concat "cat " file) t)
|
||||
(message "The file ~a does not exist." file)))
|
||||
|
||||
(defvar *surfraw-bookmark-file* nil
|
||||
"The surfraw bookmark file")
|
||||
|
||||
(defcommand sr-bookmark (bmk) ((:string "Bookmark: "))
|
||||
(surfraw "" bmk))
|
||||
(run-shell-command (concat "exec surfraw -g " bmk)))
|
||||
|
||||
(defcommand sr-bookmark-file-display () ()
|
||||
(display-file *surfraw-bookmark-file*))
|
||||
(if-let ((path (file-exists-p *surfraw-bookmark-file*)))
|
||||
(read-file-string path)
|
||||
(message "The file ~a does not exist." file)))
|
||||
|
||||
;;; surfraw.lisp ends here
|
||||
|
|
|
|||
Loading…
Reference in a new issue