Hi!

I tried to send these patches 2 times already, maybe git send-email
did something with the mail headers that the list software didn't
like?

So here I go again, this time with my email program.

Note that it should be simple to put Ivy's original bindings back into
place via defcommand-alias, but I chose not to do so, because I find
the "sr-" prefix more convenient for tab-completing surfraw bindings.


-- 
        Friedrich Delgado <frie...@nomaden.org>
                             TauPan on Ircnet and Freenode ;)
>From a53b85f4dddc0e7e028871b910db66022104c0f3 Mon Sep 17 00:00:00 2001
From: Friedrich Delgado <delg...@pre-sense.de>
Date: Thu, 9 Sep 2010 17:10:17 +0200
Subject: [PATCH 1/3] shorten surfraw.lisp somewhat by using a macro that harvests all the
 elvis...

If you want the old names back, you can use defcommand-alias.
---
 contrib/surfraw.lisp |  126 +++++++++++---------------------------------------
 1 files changed, 28 insertions(+), 98 deletions(-)

diff --git a/contrib/surfraw.lisp b/contrib/surfraw.lisp
index 66a2d12..b1a9f00 100644
--- a/contrib/surfraw.lisp
+++ b/contrib/surfraw.lisp
@@ -74,112 +74,42 @@
 
 ;;; 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)))
+          (cdr (split-string (run-shell-command "surfraw -elvi" :collect-output-p)
+                             '(#\Newline)))))
+
+(defmacro auto-define-surfraw-commands-from-elvis-list ()
+  (let ((commands nil))
+    (dolist (elvi (surfraw-elvis-list))
+      (let ((key (first elvi))
+            (description (second elvi)))
+        (push `(defcommand ,(intern (concat "sr-" key)) (search)
+                 ((:string ,(concat description ": ")))
+                 ,description
+                 (surfraw ,key search))
+              commands)
+        (push `(defcommand ,(intern (concat "sr-sel-" key)) () ()
+                 (surfraw ,key (get-x-selection)))
+              commands)))
+    (cons 'progn (reverse commands))))
+(auto-define-surfraw-commands-from-elvis-list)
 ;;; Regular surfraw commands
 
-(defcommand surfraw (engine search) 
+(defcommand surfraw (engine search)
   ((:string "What engine? ") (:string "Search for what? "))
   "Use SURFRAW to surf the net; reclaim heathen lands."
   (check-type engine string)
   (check-type search string)
   (run-shell-command (concat "exec surfraw -g " engine " " search)))
 
-(defcommand alioth (search) 
-  ((:string "Search Alioth: "))
-  (surfraw "alioth" search))
-
-(defcommand amazon (search) 
-  ((:string "Search Amazon: "))
-  (surfraw "amazon" search))
-
-(defcommand archpkg (search) 
-  ((:string "Search Arch Linux packages: "))
-  (surfraw "archpkg" search))
-
-(defcommand bbcnews (search) 
-  ((:string "Search BBC News: "))
-  (surfraw "bbcnews" search))
-
-(defcommand cddb (search)
-  ((:string "Search the CDDB: "))
-  (surfraw "cddb" search))
-
-(defcommand cnn (search)
-  ((:string "Search CNN: "))
-  (surfraw "cnn" search))
-
-(defcommand debbugs (search)
-  ((:string "Search the Debian BTS: "))
-  (surfraw "debbugs" search))
-
-(defcommand deja (search)
-  ((:string "Search Google Groups: "))
-  (surfraw "deja" search))
-
-(defcommand ebay (search)
-  ((:string "Search Ebay: "))
-  (surfraw "ebay" search))
-
-(defcommand etym (search)
-  ((:string "Search Etymology Online: "))
-  (surfraw "etym" search))
-
-(defcommand freebsd (search)
-  ((:string "Search FreeBSD info: "))
-  (surfraw "freebsd" search))
-
-(defcommand freshmeat (search)
-  ((:string "Search Freshmeat: "))
-  (surfraw "freshmeat" search))
-
-(defcommand genpkg (search)
-  ((:string "Search Gentoo packages: "))
-  (surfraw "genpkg" search))
-
-(defcommand google (search) 
-  ((:string "Search google: "))
-  (surfraw "google" search))
-
-(defcommand thesaurus (search) 
-  ((:string "Search a thesaurus: "))
-  (surfraw "thesaurus" search))
-
-(defcommand wayback (search) 
-  ((:string "Search wayback: "))
-  (surfraw "wayback" search))
-
-(defcommand webster (search) 
-  ((:string "Search the Merriam-Webster Dictionary: "))
-  (surfraw "webster" search))
-
-(defcommand wikipedia (search) 
-  ((:string "Search wikipedia: "))
-  (surfraw "wikipedia" search))
-
-;;; X selection
-
-(defmacro surfraw-selection (name engine)
-  `(defcommand ,name () ()
-     (surfraw ,engine (get-x-selection))))
-
-(surfraw-selection alioth-selection    "alioth")
-(surfraw-selection amazon-selection    "amazon")
-(surfraw-selection archpkg-selection   "archpkg")
-(surfraw-selection bbcnews-selection   "bbcnews")
-(surfraw-selection cddb-selection      "cddb")
-(surfraw-selection cnn-selection       "cnn")
-(surfraw-selection debbugs-selection   "debbugs")
-(surfraw-selection deja-selection      "deja")
-(surfraw-selection ebay-selection      "ebay")
-(surfraw-selection etym-selection      "etym")
-(surfraw-selection freebsd-selection   "freebsd")
-(surfraw-selection freshmeat-selection "freshmeat")
-(surfraw-selection genpkg-selection    "genpkg")
-(surfraw-selection google-selection    "google")
-(surfraw-selection thesaurus-selection "thesaurus")
-(surfraw-selection wayback-selection   "wayback")
-(surfraw-selection webster-selection   "webster")
-(surfraw-selection wikipedia-selection "wikipedia")
-
 ;;; Bookmarks
 
 (defun display-file (file)
-- 
1.7.1.333.g6339f67

>From 7f0a04405b6610e9dc05c0a7f6bd4c253cba0cba Mon Sep 17 00:00:00 2001
From: Friedrich Delgado <delg...@pre-sense.de>
Date: Thu, 9 Sep 2010 17:13:09 +0200
Subject: [PATCH 2/3] delete the fixmes, since I think I did fix them

---
 contrib/surfraw.lisp |   27 ---------------------------
 1 files changed, 0 insertions(+), 27 deletions(-)

diff --git a/contrib/surfraw.lisp b/contrib/surfraw.lisp
index b1a9f00..1805344 100644
--- a/contrib/surfraw.lisp
+++ b/contrib/surfraw.lisp
@@ -45,33 +45,6 @@
 ;; Note that there are also "surfraw-selection" variants on each
 ;; command that work on the X selection.
 
-;;; FIXME:
-;;
-;; - Not all elvi are supported yet. Do they need to be?
-;; - It would be pretty cool to have a macro like the
-;;   surfraw-selection one but for regular surfraw commands.
-
-;; Supported elvi (feel free to add more):
-;;
-;;   - Alioth
-;;   - Amazon
-;;   - Archpkg
-;;   - BBCNews
-;;   - CDDB
-;;   - CNN
-;;   - DebBugs
-;;   - Deja
-;;   - Ebay
-;;   - Etym
-;;   - FreeBSD
-;;   - Freshmeat
-;;   - GenPkg
-;;   - Google
-;;   - Thesaurus
-;;   - Wayback
-;;   - Webster
-;;   - Wikipedia
-
 ;;; Code:
 
 (defun split-by-- (str)
-- 
1.7.1.333.g6339f67

>From ae44408f7aed417b7909b14147dfec45b914a4be Mon Sep 17 00:00:00 2001
From: Friedrich Delgado <delg...@pre-sense.de>
Date: Thu, 9 Sep 2010 17:13:53 +0200
Subject: [PATCH 3/3] add me in the header

---
 contrib/surfraw.lisp |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/contrib/surfraw.lisp b/contrib/surfraw.lisp
index 1805344..d91699c 100644
--- a/contrib/surfraw.lisp
+++ b/contrib/surfraw.lisp
@@ -1,6 +1,7 @@
 ;; SURFRAW module for StumpWM.
 ;;
 ;; Copyright (C) 2008 Ivy Foster
+;; Copyright (C) 2010 Ivy Foster, Friedrich Delgado
 ;;
 ;; Maintainer: Ivy Foster
 ;;
-- 
1.7.1.333.g6339f67

_______________________________________________
Stumpwm-devel mailing list
Stumpwm-devel@nongnu.org
http://lists.nongnu.org/mailman/listinfo/stumpwm-devel

Reply via email to