This patch adds and documents support for command-line options. This in
preparation for a --replace option (which I have not implemented). Right
now, there are three options --replace, --help and --version . --help
and --version do what you would expect. Also, the info documentation has
been updated with the new option as well as the docs for my logout
patch.

I would also like to use this email as an opportunity to request commit
access. I have contributed several bugfixes, one minor feature and one
(sort of) major feature. These have yet to make it into the repository
and commit access would be helpful in resolving this backlog, as well as
enabling me to make my contributions to stumpwm more easily.

Thank you for your consideration,

Krzysztof Drewniak
-- 
X-Real-Email-With-Antispam: krzysdrewniak at gmail dot com
pgp key on keyserver.ubuntu.com 2388E924

From 6f4eec14247760680cf2509f3fb8e49f4006c3f3 Mon Sep 17 00:00:00 2001
From: Krzysztof Drewniak <krzysdrewn...@gmail.com>
Date: Sat, 5 Mar 2011 14:56:14 -0600
Subject: [PATCH 1/4] Aded code to parse command-line options.

---
 options.lisp |   53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 stumpwm.asd  |    1 +
 stumpwm.lisp |   19 +++++++++++++++++--
 3 files changed, 71 insertions(+), 2 deletions(-)
 create mode 100644 options.lisp

diff --git a/options.lisp b/options.lisp
new file mode 100644
index 0000000..961e37b
--- /dev/null
+++ b/options.lisp
@@ -0,0 +1,53 @@
+;; Copyright (C) 2003-2008 Shawn Betts
+;;
+;;  This file is part of stumpwm.
+;;
+;; stumpwm is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 2, or (at your option)
+;; any later version.
+
+;; stumpwm is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this software; see the file COPYING.  If not, write to
+;; the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+;; Boston, MA 02111-1307 USA
+
+;; Commentary:
+;;
+;; Options and option parsing code
+;;
+;; Code:
+
+(in-package :stumpwm)
+
+(defvar *options* nil "The structure that holds the results of the parsing of the command-line options")
+
+(defclass options ()
+  ((help :initform nil) (version :initform nil) (replace :initform nil)))
+
+(let ((options-list 
+       ;; Each element of this list is of the form 
+       ;; (option-symbol help-text &rest text-to-match)
+       '(('help "Show this help text and exit." "--help" "-h")
+	 ('version "Print the version of the program and exit." "--version" "-v")
+	 ('replace "Replace any window manager already running." "--replace"))))
+
+  (defun parse-options (args)
+    (let ((struct (make-instance 'options)))
+      (loop for i in args do
+	   (loop for (symbol help &rest matches) in options-list do
+		(when (member i matches :test #'string=)
+		  (setf (slot-value struct symbol) t))))
+      struct))
+  
+  (defun show-help ()
+    (loop for (symbol help &rest matches) in options-list do
+	 (format t "~{~a~^, ~}~20,1T~a" matches help))))
+
+(defun get-option (option &optional (struct *options*))
+  (slot-value option struct))
diff --git a/stumpwm.asd b/stumpwm.asd
index 9bb3cf8..75870ad 100644
--- a/stumpwm.asd
+++ b/stumpwm.asd
@@ -47,6 +47,7 @@
                (:file "bindings")
                (:file "events")
                (:file "help")
+	       (:file "options")
                (:file "fdump")
 	       (:file "time")
 	       (:file "mode-line")
diff --git a/stumpwm.lisp b/stumpwm.lisp
index a356e12..c19f214 100644
--- a/stumpwm.lisp
+++ b/stumpwm.lisp
@@ -58,8 +58,11 @@ loaded. When CATCH-ERRORS is nil, errors are left to be handled further up. "
           (find error-key '(xlib:window-error xlib:drawable-error xlib:match-error)))
      (dformat 4 "Ignoring error: ~s~%" error-key))
     ((eq error-key 'xlib:access-error)
-     (write-line "Another window manager is running.")
-     (throw :top-level :quit))
+     (if (get-option 'replace)
+	 (replace-wm)
+	 (progn
+	   (write-line "Another window manager is running.")
+	   (throw :top-level :quit))))
      ;; all other asynchronous errors are printed.
      (asynchronous
       (message "Caught Asynchronous X Error: ~s ~s" error-key key-vals))
@@ -196,6 +199,16 @@ of those expired."
 	    :local)
 	   (t :internet)))))
 
+(defun handle-options ()
+  (setf *options* (parse-options (argv)))
+  (let ((option (or (and (get-option 'help) 'help) 
+		    (and (get-option 'version) 'version))))
+    (when option
+      (case option
+	('help (show-help))
+	('version (format t *version*)))
+      (throw :top-level :quit))))
+
 (defun stumpwm-internal (display-str)
   (multiple-value-bind (host display screen protocol) (parse-display-string display-str)
     (declare (ignore screen))
@@ -219,6 +232,8 @@ of those expired."
                    (if success
                        (and *startup-message* (message *startup-message* (print-key *escape-key*)))
                        (message "^B^1*Error loading ^b~A^B: ^n~A" rc err))))
+	       ;; Options that must be acted on here are acted on
+	       (handle-options)
                (when *last-unhandled-error*
                  (message-no-timeout "^B^1*StumpWM Crashed With An Unhandled Error!~%Copy the error to the clipboard with the 'copy-unhandled-error' command.~%^b~a^B^n~%~%~a"
                           (first *last-unhandled-error*) (second *last-unhandled-error*)))
-- 
1.7.1

From fc12ef7e8fe197fc23580243c48809bf1a162f9c Mon Sep 17 00:00:00 2001
From: Krzysztof Drewniak <krzysdrewn...@gmail.com>
Date: Sat, 5 Mar 2011 15:35:25 -0600
Subject: [PATCH 2/4] Added fixes for options stuff

---
 options.lisp |   17 ++++++++++-------
 stumpwm.lisp |    9 ++++++---
 2 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/options.lisp b/options.lisp
index 961e37b..f5608cb 100644
--- a/options.lisp
+++ b/options.lisp
@@ -33,21 +33,24 @@
 (let ((options-list 
        ;; Each element of this list is of the form 
        ;; (option-symbol help-text &rest text-to-match)
-       '(('help "Show this help text and exit." "--help" "-h")
-	 ('version "Print the version of the program and exit." "--version" "-v")
-	 ('replace "Replace any window manager already running." "--replace"))))
+       '((help "Show this help text and exit." "--help" "-h")
+	 (version "Print the version of the program and exit." "--version" "-v")
+	 (replace "Replace any window manager already running." "--replace"))))
 
   (defun parse-options (args)
     (let ((struct (make-instance 'options)))
       (loop for i in args do
-	   (loop for (symbol help &rest matches) in options-list do
+	   (loop for (symbol help . matches) in options-list do
 		(when (member i matches :test #'string=)
 		  (setf (slot-value struct symbol) t))))
       struct))
   
   (defun show-help ()
-    (loop for (symbol help &rest matches) in options-list do
-	 (format t "~{~a~^, ~}~20,1T~a" matches help))))
+    (loop for (symbol help . matches) in options-list do
+	 (format t "~{~a~^, ~}~20,1T~a~%" matches help))))
 
 (defun get-option (option &optional (struct *options*))
-  (slot-value option struct))
+  ;; Fallback in the event of code that fires off early [not needed any more]
+  ;; (when (not struct)
+  ;;   (setf struct (parse-options (argv))))
+  (slot-value struct option))
diff --git a/stumpwm.lisp b/stumpwm.lisp
index c19f214..a6512e9 100644
--- a/stumpwm.lisp
+++ b/stumpwm.lisp
@@ -26,11 +26,15 @@
 (export '(cancel-timer
 	  run-with-timer
 	  stumpwm
-	  timer-p))
+	  timer-p
+	  *version*))
 
 
 ;;; Main
 
+;; Defining *version* here to avoid warnings
+(defvar *version* nil)
+
 (defun load-rc-file (&optional (catch-errors t))
   "Load the user's .stumpwmrc file or the system wide one if that
 doesn't exist. Returns a values list: whether the file loaded (t if no
@@ -210,6 +214,7 @@ of those expired."
       (throw :top-level :quit))))
 
 (defun stumpwm-internal (display-str)
+  (handle-options) ;;get --help and --version out of the way now
   (multiple-value-bind (host display screen protocol) (parse-display-string display-str)
     (declare (ignore screen))
     (setf *display* (xlib:open-display host :display display :protocol protocol)
@@ -232,8 +237,6 @@ of those expired."
                    (if success
                        (and *startup-message* (message *startup-message* (print-key *escape-key*)))
                        (message "^B^1*Error loading ^b~A^B: ^n~A" rc err))))
-	       ;; Options that must be acted on here are acted on
-	       (handle-options)
                (when *last-unhandled-error*
                  (message-no-timeout "^B^1*StumpWM Crashed With An Unhandled Error!~%Copy the error to the clipboard with the 'copy-unhandled-error' command.~%^b~a^B^n~%~%~a"
                           (first *last-unhandled-error*) (second *last-unhandled-error*)))
-- 
1.7.1

From 47421514ba7f8c3251661e7aa59fc98f44c14832 Mon Sep 17 00:00:00 2001
From: Krzysztof Drewniak <krzysdrewn...@gmail.com>
Date: Sat, 5 Mar 2011 16:58:28 -0600
Subject: [PATCH 3/4] Documented all my changed
 options.lisp: Fixed some small stuff, made is possible to autogenerate
 options docs
 stumpwm.texi.in: Added the docs for this stuff

---
 options.lisp    |   10 +++++++---
 stumpwm.texi.in |   31 ++++++++++++++++++++++++++++---
 2 files changed, 35 insertions(+), 6 deletions(-)

diff --git a/options.lisp b/options.lisp
index f5608cb..fc3a062 100644
--- a/options.lisp
+++ b/options.lisp
@@ -45,12 +45,16 @@
 		  (setf (slot-value struct symbol) t))))
       struct))
   
-  (defun show-help ()
-    (loop for (symbol help . matches) in options-list do
-	 (format t "~{~a~^, ~}~20,1T~a~%" matches help))))
+  (defun show-help (&optional (stream t))
+    (apply #'concatenate 'string
+	   (loop for (symbol help . matches) in options-list collect
+		(format stream "~{~a~^, ~}~20,1T~a~%" matches help)))))
 
 (defun get-option (option &optional (struct *options*))
   ;; Fallback in the event of code that fires off early [not needed any more]
   ;; (when (not struct)
   ;;   (setf struct (parse-options (argv))))
   (slot-value struct option))
+
+(defvar *help-text* :autogenerates-for-the-docs 
+  (format nil "@verbatim~%~a@end verbatim~%" (show-help nil)))
diff --git a/stumpwm.texi.in b/stumpwm.texi.in
index 4b6cdd1..75cb89a 100644
--- a/stumpwm.texi.in
+++ b/stumpwm.texi.in
@@ -83,7 +83,8 @@ This document explains how to use The Stump Window Manager.
 @end ifinfo
 
 @menu
-* Introduction::                
+* Introduction::
+* Command-Line Options::                
 * Key Bindings::                
 * Commands::                    
 * Message and Input Bar::       
@@ -112,6 +113,10 @@ Introduction
 * Interacting with the Lisp process::  
 * Contact the StumpWM developers::  
 
+Command-Line Options
+
+* List of Command-Line Options::
+
 Key Bindings
 
 * List of Default Keybindings::  
@@ -168,7 +173,7 @@ Hacking
 @end detailmenu
 @end menu
 
-@node Introduction, Key Bindings, Top, Top
+@node Introduction, Command-Line Options, Top, Top
 @chapter Introduction
 StumpWM is an X11 window manager written entirely in Common Lisp. Its
 user interface goals are similar to ratpoison's but with an emphasis on
@@ -304,7 +309,23 @@ is restricted to subscribers to keep spam out of the archives.
 The StumpWM IRC channel can be found on Freenode at
 @uref{irc://irc.freenode.net/#stumpwm, @code{#stumpwm}}.
 
-@node Key Bindings, Commands, Introduction, Top
+@node Command-Line Options, Key Bindings, Introduction, Top
+@chapter Command-Line Options
+StummpWM currently has very few command-line options. Please note that
+to prevent option parsing by lisp, the sequence @code{--} must be on the
+command line before the usage of the options @code{--help} and
+@code{--version}.
+
+@menu
+* List of Command-Line Options::
+@end menu
+
+@node List of Command-Line Options,  , Command-Line Options, Command-Line Options
+@section List of Command-Line Options
+This is all the docs we have for now.
+### *help-text*
+
+@node Key Bindings, Commands, Command-Line Options, Top
 @chapter Key Bindings
 StumpWM is controlled entirely by keystrokes and Lisp commands. It
 mimics GNU Screen's keyboard handling. StumpWM's default prefix key is
@@ -402,6 +423,10 @@ Prompt for a shell command to run via @file{/bin/sh}. All output is discarded.
 If the screen is split into multiple frames, one split will be
 undone. If there is only one split, the effect will be the same as @kbd{C-t Q}.
 
+@item C-t C-t C-L
+End the stumpwm process, logging you out, after prompting to check if
+you are sure you would like to do that.
+
 @item C-t o
 @itemx C-t TAB
 If the screen is split into multiple frames, focus shifts to the
-- 
1.7.1

From ec9760a9dd289e5ff9668b8c56fc3445009ec291 Mon Sep 17 00:00:00 2001
From: Krzysztof Drewniak <krzysdrewn...@gmail.com>
Date: Sat, 5 Mar 2011 19:34:39 -0600
Subject: [PATCH 4/4] Fixed a warning with a stub while WM replacing is implemented

---
 stumpwm.lisp |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/stumpwm.lisp b/stumpwm.lisp
index a6512e9..59df432 100644
--- a/stumpwm.lisp
+++ b/stumpwm.lisp
@@ -213,6 +213,11 @@ of those expired."
 	('version (format t *version*)))
       (throw :top-level :quit))))
 
+(defun replace-wm ()
+  "Replace the currently running window manager, if any."
+  (write-line "Function not implemented.")
+  (throw :top-levl :quit))
+
 (defun stumpwm-internal (display-str)
   (handle-options) ;;get --help and --version out of the way now
   (multiple-value-bind (host display screen protocol) (parse-display-string display-str)
-- 
1.7.1

Attachment: signature.asc
Description: This is a digitally signed message part

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

Reply via email to