 ;;        set of keywords rather than call gnugol
 ;;        (if (search-forward (concat "[[Search: " str )) () (gnugol-cmd str)))?
 ;; FIXME: Sanitize the shell arguments to prevent abuse !! For example no CRs
-;;        regexp? Maybe the shell does it for me? What?
+;;        regexp? I'm *nearly* certain that url escaping and shell quoting the args
+;;        is good enough.
 ;; FIXME: actually, going to the 4th char in on the title would work best
 ;; FIXME: make gnugol opts be local
 ;; FIXME: CNTR-U should set the position
 ;; FIXME: a query with the same keywords as the previous should fetch more 
 ;;        results (maybe)
-;; (shell-quote-argument str )
+
 (defun gnugol (str)
-  "search the web via gnugol, bring up results in org buffer"
+  "Search the web via gnugol, bring up results in org buffer."
   (interactive "sSearch: ")
   (if (< (length str) gnugol-search-maxlen)
       (let (newbuffer)
-	(setq gnugol-opts (concat " " gnugol-default-opts " -n " (int-to-string gnugol-default-nresults)))
+	(setq gnugol-opts (concat (if gnugol-default-opts (concat gnugol-default-opts) ()) 
+				  (if gnugol-default-nresults (concat " -n " (int-to-string gnugol-default-nresults) ()))
+				  (if gnugol-default-engine (concat " -e " gnugol-default-engine))
+				  (if gnugol-default-output-format (concat " -o " gnugol-default-output-format) ())
+				  (if gnugol-default-header (concat " -H " gnugol-default-header) ())
+				  (if gnugol-default-footer (concat " -F " gnugol-default-footer) ())
+;;				  (if gnugol-default-safe-mode (concat " -S " gnugol-default-safe-mode) ())
+				  (if gnugol-default-input-language (concat " -l " gnugol-default-input-language) ())
+				  (if gnugol-default-output-language (concat " -L " gnugol-default-output-language) ())
+				  ))	
+	(setq gnugol-full-cmd  (concat gnugol-cmd " " gnugol-opts " -U -- " 
+				       (shell-quote-argument 
+					(gnugol-url-encode str))))
+;; FIXME: Open the file, or reload the file if not a *gnugol* buffer
 	(setq newbuffer (get-buffer-create gnugol-default-output-buffer))
 	(set-buffer newbuffer)
+;; FIXME: Set mode of buffer based on the extension
 	(org-mode)
 	(goto-char (point-min))
 	;; FIXME what we want to do is something like this but I'm getting it wrong
 	;; (if (search-forward (concat "[Search: " str "]")) () 
+;;	(message "%s" gnugol-full-cmd)	
 	(save-excursion 
 	  (insert-string (concat "* [[gnugol: " str "][Search: " str "]]\n"))
 	  (insert 
-	   (shell-command-to-string 
-	    (concat gnugol-cmd gnugol-opts " -U -- " 
-		    (shell-quote-argument 
-		     (gnugol-url-encode str)))
-	    ))
-	  ;; (message (concat gnugol-cmd gnugol-opts " -- " str))
+	   (shell-command-to-string gnugol-full-cmd)
+	    )
 	  (switch-to-buffer newbuffer)
-	  ))
+	  )
+	;; (goto-char (+ point-min 4))
+	)
     ( (beep) (message "search string too long"))))
 
 (defun gnugol-search-selection ()

      (beep)
      (message "Region not active"))))


;; FIXME: NOTHING BELOW HERE ACTUALLY WORKS YET
;; FIXME: For the into-pt stuff, be sensitive to the mode

  :type 'string
  :group 'gnugol)

(defcustom gnugol-default-opts nil
  "Additional default options for gnugol."
  :type 'string
  :group 'gnugol)

(defcustom gnugol-default-engine nil
  "Default search engine backend for gnugol. Presently supported are:
  google: Full support (license key recommended)
  bing: (with a license key)
  dummy: (useful for testing)
  credits: various options like about, licenses etc."
  :type 'string
  :group 'gnugol)

