Prefix arguments



Hi,

now that I have a dual head I must finally migrate to a more capable sawfish version.

To see how big the differences are, I commented out the things that choke, but the one that would really hurt me is the little jewel I attached.  To me, 30 years an Emacs fan, especially grow-pack would be useless without prefix arguments!  Afaict various commands accept them, but none set them.

Not sure if the way I did this 10 years ago still matches your programming style.  My bind-prefix-keys function that must be called in the rc file is debatable.  If I were to choose, those key bindings would be standard — feel free to integrate this in sawfish.wm.commands.  But if you find that too intrusive, you are welcome to have a more elegant, i.e. easily customizable, way of setting this.

regards — Daniel

coralament / best Grötens / liebe Grüße / best regards / elkorajn salutojn
Daniel Pfeiffer

-- 
lerne / learn / apprends / lär dig / ucz się    Esperanto:
                    http://lernu.net  /  http://ikurso.net
#| prefix.jl -- emacs style prefix arguments

   Copyright (C) 2001, 02 Daniel Pfeiffer <occitan esperanto org>

   This file is part of sawfish.

   sawfish 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.

   sawfish 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 sawfish; see the file COPYING.  If not, write to
   the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|#

(define-structure sawfish.wm.commands.prefix

    (export numeric-arg
	    negative-arg
	    universal-arg
	    set-prefix-arg
	    bind-prefix-keys)

    (open rep
	  sawfish.wm.commands
	  sawfish.wm.events)

  (define (numeric-arg digit arg)
    "Add a digit to the prefix-arg."
    (setq digit (string->number (substring digit (1- (length digit))))
	  prefix-arg (cond
		      ((numberp arg)
		       ((if (< arg 0) - +) (* arg 10) digit))
		      ((eq arg '-)
		       (- digit))
		      (digit))
	  this-command last-command))

  (define (negative-arg arg)
    "Negate the prefix-arg."
    (setq prefix-arg (cond
		      ((numberp arg)
		       (* arg -1))
		      ((eq arg '-)
		       nil)
		      ('-))
	  this-command last-command))

  (define (universal-arg arg)
    "Set a special universal prefix-arg which usually increases by factor 4."
    (setq prefix-arg (cond
		      ((consp arg)
		       (rplaca arg (* 4 (car arg)))
		       arg)
		      ((cons 4 nil)))
	  this-command last-command))

  (define (set-prefix-arg arg)
    "Prompt for the prefix-arg.  You can enter a positive or negative number,
or nothing to unset the prefix arg."
    (require 'sawfish.wm.util.prompt)
    (let ((str (if arg
		   (number->string (prefix-numeric-argument arg))
		 ""))
	  (cmd last-command))
      (setq arg ())
      (while (not (numberp arg))
	(setq str (prompt "Enter numeric prefix: " str)
	      arg (read-from-string str)))
      (setq prefix-arg arg
	    this-command cmd)))

  (define-command 'numeric-arg numeric-arg #:spec "E\nP")
  (define-command 'negative-arg negative-arg #:spec "P")
  (define-command 'universal-arg universal-arg #:spec "P")
  (define-command 'set-prefix-arg set-prefix-arg #:spec "P")

  (define (bind-prefix-keys)
    (bind-keys global-keymap
	       "W-0" 'numeric-arg
	       "W-1" 'numeric-arg
	       "W-2" 'numeric-arg
	       "W-3" 'numeric-arg
	       "W-4" 'numeric-arg
	       "W-5" 'numeric-arg
	       "W-6" 'numeric-arg
	       "W-7" 'numeric-arg
	       "W-8" 'numeric-arg
	       "W-9" 'numeric-arg
	       "W--" 'negative-arg
	       "W-u" 'universal-arg)))


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]