Re: keyboard-macro-timer.el

2007-07-20 Thread Mathias Dahl
Richard Stallman [EMAIL PROTECTED] writes:

 It occurs to me that it would be more general to repeat the next or
 previous command at a given interval.  If what you want to repeat is
 a keyboard macro, then you type a command to run the keyboard macro.

True, that would be more general.

 It is probably just as convenient, and maybe simpler too.  Would you
 like to give that a try?

For executing previous command I did some investigation and looked up
how `repeat' does it and it was way too complicated to me with a lot
of handling of special cases. And when it comes to reading the next
command, I would not even know where to begin. I see that there is the
function `read-command' to read a commands name, but that does not
seem very convenient. I guess I could also read the next keyboard
sequence, and even if I manage executing the bound command, what if
that command would require user interaction, e.g. response in the
minibuffer?

By forcing the user to record a keyboard macro for what he wants to
repeat, I get around all these problems, problems that didn't even
exist before you suggested the above... :)

Anyway, thanks for the suggestion, it is a good idea, but way over my
elisp capabilities.

What could be a good idea, however, would be to add something similar
to my hack to the kmacro package. I think it would fit quite well in
there.

/Mathias
___
gnu-emacs-sources mailing list
gnu-emacs-sources@gnu.org
http://lists.gnu.org/mailman/listinfo/gnu-emacs-sources


Re: keyboard-macro-timer.el

2007-07-20 Thread Richard Stallman
For executing previous command I did some investigation and looked up
how `repeat' does it and it was way too complicated to me with a lot
of handling of special cases.

We could move some of that code to a subroutine which you could call.
That should be pretty straightforward.

Having similar interfaces for the two repetition commands
would also be a plus for simplicity and coherence.


___
gnu-emacs-sources mailing list
gnu-emacs-sources@gnu.org
http://lists.gnu.org/mailman/listinfo/gnu-emacs-sources


keyboard-macro-timer.el

2007-07-19 Thread Mathias Dahl

For your pleasure :)

/Mathias

;;; keyboard-macro-timer.el --- Run last keyboard macro with a timer

;; Copyright (C) 2007 Mathias Dahl
;;
;; Version: 0.1
;; Keywords: convenience, keyboard macros, timers
;; Author: Mathias Dahl [EMAIL PROTECTED]

;; This file is not part of GNU Emacs.

;; GNU Emacs 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.

;; GNU Emacs 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 GNU Emacs; see the file COPYING.  If not, write to the
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.

;;; Commentary:

;;
;; Sometimes I record a small keyboard macro just to run some simple
;; command over and over again, each X number of seconds, often to
;; execute some SQL query or running some other command to monitor
;; some process.  It is easy enough to execute the macro with some
;; specially bound key, but why not letting Emacs do it for me
;; instead?  That's why I made this small hack.  Another example of
;; usage could be to have it act as a simple document reader; just
;; record a keyboard macro to step one line down, and then start the
;; timer.
;;
;; To install it, put the file in your load path and add these lines
;; to your .emacs:
;;
;;   (autoload 'keyboard-macro-timer-start keyboard-macro-timer
;;   Execute last keyboard macro with a timer. t)
;;
;; To use it, call `keyboard-macro-timer-start' after you have
;; recorded a keyboard macro.  You will be prompted for a number of
;; seconds to wait before executing the macro the first time and for
;; the interval, in seconds, between invocations.  Both values may be
;; integers or floating point numbers so you can specify fractions of
;; a second and both have default values
;; (`keyboard-macro-timer-default-start-in' and
;; `keyboard-macro-timer-default-interval') so that you can just type
;; `RET' to accept the defaults.  The default values are configurable.
;;
;; To stop the execution, call `keyboard-macro-timer-cancel'.
;;
;; Make it really easy to stop the timer by binding the cancel command
;; to a key:
;;
;;  (global-set-key [f6] 'keyboard-macro-timer-cancel)
;;
;; Try it now: type `C-x (' to start a keyboard macro, then type `C-f'
;; to step one character forward.  Stop macro recording with `C-x
;; )'. Next, do M-x keyboard-macro-timer-start and type `RET' at both
;; prompts.  Stop it the timer by running
;; `keyboard-macro-timer-cancel'.
;;
;; Only tested on Emacs 22.1.
;;


;;; History:
;;
;; Version 0.1, 2007-07-19
;;
;; * First release.
;;

;;; Code:

(defvar keyboard-macro-timer nil
  Timer for running keyboard macro.)

(defcustom keyboard-macro-timer-default-start-in 2
  Default number of seconds for the START-IN argument.
  :type 'number
  :group 'keyboard-macro-timer)

(defcustom keyboard-macro-timer-default-interval 2
  Default number of seconds for the INTERVAL argument.
  :type 'number
  :group 'keyboard-macro-timer)

(defun keyboard-macro-timer-start (start-in interval)
  Execute last keyboard macro with a timer.
START-IN defines the number of seconds until the macro is first
run, and INTERVAL defines the number of seconds between each
call.  Both arguments may be integers or floating point numbers
so you can specify fractions of a second.
  (interactive (let ((start-in (read-number
Start in: 
keyboard-macro-timer-default-start-in))
 (interval (read-number
Interval: 
keyboard-macro-timer-default-interval)))
 (list start-in interval)))
  (setq keyboard-macro-timer
(run-with-timer
 start-in interval
 (lambda ()
   (kmacro-end-or-call-macro 1)

(defun keyboard-macro-timer-cancel ()
  Cancel execution of keyboard macro timer.
  (interactive)
  (cancel-timer keyboard-macro-timer))

(provide 'keyboard-macro-timer)

;;; keyboard-macro-timer.el ends here
___
gnu-emacs-sources mailing list
gnu-emacs-sources@gnu.org
http://lists.gnu.org/mailman/listinfo/gnu-emacs-sources