(defun ee-next-line (&optional arg try-vscroll)
"Like `next-line', but always moves by \"buffer lines\".
See: (find-enode \"Moving Point\" \"`line-move-visual'\")\n
Note: the variable `line-move-visual' was introduced in Emacs in
2008jul11. On versions of Emacs older than that this function
behaves exactly like `next-line'."
(let ((line-move-visual nil))
(next-line arg try-vscroll)))
(defun eek (s &optional e count)
"Execute the string S (or the region between S and E) as a keyboard macro.
See `edmacro-mode' for the exact format.\n
An example: (eek \"C-x 4 C-h\")"
(interactive "r")
(execute-kbd-macro (read-kbd-macro (ee-se-to-string s e)) count))
(defun eek0 (kbmacro &optional count)
"This is similar to `eek', but uses the low-level formats for macros.
Example: (eek \"\\C-x4\\C-h\")"
(execute-kbd-macro kbmacro count))
(defvar eesteps-list ())
(defvar eesteps-pos 0)
(defun eesteps (list)
"Set the LIST of steps that `eesteps-do-step' will execute.\n
Here's an example: run\n
(eesteps '(\"C-x b * scratch * RET ;;; change to the buffer *scratch*\"
\"foobar\"
\"3*<left>\"
(insert \"!\")))\n
then type \\[eesteps-do-step] four times.\n
Each step is either a string -- meaning a series of keys, in the
format used by `edmacro-mode' -- or a sexp to be evaluated."
(setq eesteps-pos 0)
(setq eesteps-list list)
`(,(length list) steps stored - use <f12> to execute a step))
(defun eesteps-perform (step &rest rest)
(if (stringp step)
(eek step)
(eval step))
(if rest (apply 'eesteps-perform rest)))
(defun eesteps-do-step (&optional arg)
(interactive "P")
(if (>= eesteps-pos (length eesteps-list))
(error "No more steps"))
(if (eq arg 0)
(message "Next step: %d = %S" eesteps-pos (nth eesteps-pos eesteps-list))
(eesteps-perform (nth eesteps-pos eesteps-list))
(setq eesteps-pos (1+ eesteps-pos))))
(defun eepaste-one-line ()
"Paste (yank) the first line of the top of the kill-ring here and do a RET."
(interactive)
(let ((bigstr (car kill-ring)))
(if (equal bigstr "") (error "No more lines"))
(string-match "^\\([^\n]*\\)\\(\n\\|$\\)" bigstr)
(let ((line (match-string 1 bigstr)) (rest (substring bigstr (match-end 0)))) (if (string-match "^*\\(.*\\)" line) (ee-eval-string (match-string 1 line)) (insert line) (call-interactively (key-binding "\r"))) (setcar kill-ring rest))))
(defun eestore (s &optional e)
"Store the region between S and E in the kill ring."
(kill-new (ee-se-to-string s e))
(format "Stored in the kill-ring"))
(eeb-define 'eestore-bounded 'eestore 'ee-delimiter-hash nil t t)
**
(defvar eepitch-code '(error "eepitch not set up"))
(defvar eepitch-target-buffer nil)
(defun eepitch-prepare-target-buffer ()
"Run `eepitch-code' and store the name of the resulting buffer in `eepitch-target-buffer'."
(save-window-excursion
(eval eepitch-code)
(setq eepitch-target-buffer (current-buffer))))
(defun eepitch-display-target-buffer ()
"Display the buffer `eepitch-target-buffer' in another window."
(if (not (get-buffer-window eepitch-target-buffer))
(let ((pop-up-windows t)
(same-window-buffer-names nil))
(display-buffer eepitch-target-buffer))))
(defun eepitch (code)
"Set the target buffer for pitching lines to; CODE is something like `(shell)'.
To pitch lines to the target buffer, use `\\[eepitch-this-line]'.
As with `eechannel', lines starting with `*' are executed as Lisp;
other lines are sent.
There's a (trivial) example of usage below; each line is meant to
be executed with `\\[eepitch-this-line]'. For a convenient way to
generate the three \"*\" lines at once - by typing just \"shell\"
and then `\\[ee-wrap-eepitch]' - see `ee-wrap-eepitch' and
`eepitch-shell'.
* (eepitch '(shell))
* (eepitch-kill)
* (eepitch '(shell))
cd /tmp/
pwd
"
(if (not (listp code))
(error "eepitch is no longer a macro - quote the code!"))
(setq eepitch-code code)
(eepitch-prepare-target-buffer)
(eepitch-display-target-buffer))
(defun eepitch-line (line)
(save-selected-window
(select-window (get-buffer-window eepitch-target-buffer))
(insert line) (call-interactively (key-binding "\r"))))
(defun eepitch-not-this-buffer ()
(if (eq (current-buffer) eepitch-target-buffer)
(error "Can't pitch to the current buffer")))
(defun eepitch-this-line ()
"Pitch this line to the target buffer, or eval it as lisp if it starts with `*'.
See `eepitch' and the source code."
(interactive)
(let ((line (buffer-substring (ee-bol) (ee-eol)))) (if (string-match "^*\\(.*\\)" line) (ee-eval-string (match-string 1 line)) (eepitch-prepare-target-buffer) (eepitch-display-target-buffer) (eepitch-not-this-buffer) (eepitch-line line))) (ee-next-line 1))
(defun eepitch-kill ()
"Kill the `eepitch-target-buffer'. See `eepitch' and the source code."
(interactive)
(eepitch-prepare-target-buffer) (eepitch-display-target-buffer) (eepitch-not-this-buffer) (save-selected-window (select-window (get-buffer-window eepitch-target-buffer)) (ee-kill-this-buffer)))
(defun eepitch-comint (name program-and-args)
"Set `eepitch' to run PROGRAM-AND-ARGS in comint mode, in the buffer \"*NAME*\"."
(eepitch `(find-comintprocess ,name ',program-and-args)))
(defun eepitch-shell ()
"Same as (eepitch '(shell)). See `eepitch' and `ee-wrap-eepitch'."
(interactive)
(eepitch '(shell)))
(defun eepitch-shell2 () (interactive) (eepitch '(shell "*shell 2*")))
(defun eepitch-eshell () (interactive) (eepitch '(eshell)))
(defun eepitch-lua51 () (interactive) (eepitch-comint "lua51" "lua51"))
(defun eepitch-python () (interactive) (eepitch-comint "python" "python"))
(defun eepitch-ruby () (interactive) (eepitch-comint "ruby" "irb1.8"))
(defun eepitch-gnuplot () (interactive) (eepitch-comint "gnuplot" "gnuplot"))
(defun eepitch-wish () (interactive) (eepitch-comint "wish" "wish"))
(defun eepitch-tcl () (interactive) (eepitch-comint "tclsh" "tclsh"))
(defun eepitch-tclsh () (interactive) (eepitch-comint "tclsh" "tclsh"))
(defun eepitch-expect () (interactive) (eepitch-comint "expect" "expect"))
(defun eepitch-gforth () (interactive) (eepitch '(run-forth "gforth")))
(defun ee-eepitch-comint (dir name program-and-args)
"Like `eepitch-comint', but run PROGRAM-AND-ARG at the directory DIR.
DIR is expanded with `ee-expand'; the result of the expansion
must be absolute, and must end with a slash."
(eepitch `(ee-find-comintprocess (ee-expand ,dir) ,name ',program-and-args)))
(defun eepitch-latex () (interactive) (ee-eepitch-comint "/tmp/" "latex" "latex"))
(defun eepitch-tex () (interactive) (ee-eepitch-comint "/tmp/" "tex" "tex"))
(defun eepitch-mf () (interactive) (ee-eepitch-comint "/tmp/" "mf" "mf"))
(define-key eegud-keys-mode-map "\M-k" 'eegud-kill-this-buffer)
(defun eegud-kill-this-buffer ()
(interactive)
(delete-other-windows)
(ee-kill-this-buffer))
(defvar ee-gud-escript-window nil
"An internal variable used to simplify the code of `eepitch-gdb'.
The \"e-script window\" is the upper-left quadrant of the frame.")
(defvar ee-gud-gud-window nil
"An internal variable used to simplify the code of `eepitch-gdb'.
The \"gud window\" is the lower-left quadrant of the frame.")
(defvar ee-gud-source-window nil
"An internal variable used to simplify the code of `eepitch-gdb'.
The \"source window\" is the right half of the frame.")
(defun eepitch-gud-window-setup ()
(interactive)
(delete-other-windows)
(split-window-horizontally) (split-window-vertically) (setq ee-gud-escript-window (selected-window)) (setq ee-gud-gud-window (next-window)) (setq ee-gud-source-window (next-window (next-window))))
(defun eepitch-gdb (buffer-name gdb-prog-and-args)
(eepitch-gud-window-setup)
(with-selected-window ee-gud-gud-window
(if (get-buffer buffer-name)
(find-ebuffer buffer-name)
(gdb gdb-prog-and-args)
(eegud-keys-mode 1)))
(setq eepitch-code `(find-ebuffer ,buffer-name)))
(defun eepitch-gdb-kill (buffer-name)
(if (get-buffer buffer-name) (kill-buffer buffer-name))
(delete-other-windows))
'(
(defun eepitch-gdb-lua ()
(eepitch-gdb "*gud-lua" "gdb --annotate=3 --quiet ~/usrc/lua-5.1.2/src/lua"))
(defun eepitch-gdb-lua-kill ()
(eepitch-gdb-kill "*gud-lua"))
(defun eepitch-gdb-lua ()
(eepitch-gdb "*gud-lua_O0*" "gdb --annotate=3 --quiet ~/usrc/lua-5.1.2/src/lua_O0"))
(defun eepitch-gdb-lua-kill ()
(eepitch-gdb-kill "*gud-lua_O0*"))
* (eepitch-gdb-lua)
* (eepitch-gdb-lua-kill)
* (eepitch-gdb-lua)
br main
run
n
)
**
(defvar eechannel-default nil)
(defun eechannel-strfile (channel)
(ee-expand (format "$EEVTMPDIR/eeg.%s.str" channel)))
(defun eechannel-pidfile (channel)
(ee-expand (format "$EEVTMPDIR/eeg.%s.pid" channel)))
(defun eechannel-pid (channel)
"Return the pid stored in the eeg.CHANNEL.pid file, as a string (or nil on error)."
(let ((pidfile (eechannel-pidfile channel)))
(if (file-exists-p pidfile)
(ee-no-trailing-nl (ee-read-file pidfile)))))
(defun eechannel-kill (channel sig)
"Send the signal SIG to the process listening on the channel CHANNEL."
(find-callprocess0 (format "kill %s %s" sig (eechannel-pid channel))))
(defun eechannel-send (channel str)
"Send STR through channel CHANNEL (or through channel `eechannel-default')."
(setq channel (or channel eechannel-default))
(write-region str nil (eechannel-strfile channel))
(find-callprocess0 (format "kill -USR1 %s" (eechannel-pid channel))))
(defun eechannel-this-line () (interactive)
"Send the current line through the channel `eechannel-default', and go down.
If the line starts with a `*' then evaluate it as lisp instead of sending it."
(let ((line (buffer-substring (ee-bol) (ee-eol)))) (if (string-match "^*\\(.*\\)" line) (ee-eval-string (match-string 1 line)) (eechannel-send nil (concat line "\n"))) (ee-next-line 1)))
(defun eechannel (channel)
"Set the default channel to CHANNEL."
(interactive "sDefault channel: ")
(setq eechannel-default channel))
(defun eechannel-pid-running-p (pid)
"Return t if a process with pid PID is running. This is linux-specific."
(file-exists-p (format "/proc/%s" pid)))
(defun eechannel-args-ne (channel prog-and-args)
`(,(ee-expand "$EEVDIR/eegchannel") ,channel
,@(ee-split prog-and-args)))
(defun eechannel-create-ne (channel prog-and-args)
(find-bgprocess-ne (eechannel-args-ne channel prog-and-args)))
(defun eechannel-assert-ne (channel prog-and-args)
(let ((pid (eechannel-pid channel)))
(if (eechannel-pid-running-p (eechannel-pid channel))
(message "Channel %s (pid %s) looks alive, reusing" channel pid)
(eechannel-create-ne channel prog-and-args))))
(defun eechannel-args (channel prog-and-args)
(eechannel-args-ne channel (ee-split-and-expand prog-and-args)))
(defun eechannel-create (channel prog-and-args)
(eechannel-create-ne channel (ee-split-and-expand prog-and-args)))
(defun eechannel-assert (channel prog-and-args)
(eechannel-assert-ne channel (ee-split-and-expand prog-and-args)))
(defun eexterm-args-ne (channel prog-and-args xterm-args)
"Return a list of arguments for running a xterm listening on CHANNEL.
Try these examples:
(eexterm-args-ne \"A\" nil nil)
(eexterm-args-ne \"A\" '(\"ssh\" \"foo@bar\") \"-geometry 80x20\")"
`("xterm"
"-T" ,(format "channel %s" channel)
,@(ee-split xterm-args)
"-e" ,(ee-expand "$EEVDIR/eegchannel") ,channel
,@(ee-split (or prog-and-args (ee-expand "$SHELL")))))
(defun eexterm-create-ne (channel prog-and-args xterm-args)
"Start a xterm listening on CHANNEL. See `eexterm-args-ne'."
(find-bgprocess-ne (eexterm-args-ne channel prog-and-args xterm-args)))
(defun eexterm-ne (channel prog-and-args xterm-args)
"Set the default channel to CHANNEL; create an xterm listening on CHANNEL if needed."
(interactive "sDefault channel: ")
(setq eechannel-default channel)
(if (eechannel-pid-running-p (eechannel-pid channel))
(message "Reusing xterm at channel %s" channel)
(eexterm-create-ne channel prog-and-args xterm-args)))
(defun eexterm-args (channel &optional prog-and-args xterm-args)
(eexterm-args-ne channel (ee-split-and-expand prog-and-args) xterm-args))
(defun eexterm-create (channel &optional prog-and-args xterm-args)
(eexterm-create-ne channel (ee-split-and-expand prog-and-args) xterm-args))
(defun eexterm (channel &optional prog-and-args xterm-args)
"Set the default channel to CHANNEL; create an xterm listening on CHANNEL if needed."
(interactive "sDefault channel: ")
(eexterm-ne channel (ee-split-and-expand prog-and-args) xterm-args))
(defalias 'eechannel-xterm 'eexterm)
(defun eexterm-kill (&optional channel sig)
(interactive)
(eechannel-kill (or channel eechannel-default) (or sig "")))
'(
(defun eexterm-create (channel &optional prog-and-args xterm-args)
"Create an xterm listening on CHANNEL."
(interactive "sChannel: ")
(find-bgprocess-ne
`("xterm"
"-T" ,(format "channel %s" channel)
,@xterm-args
"-e" ,(ee-expand "$EEVDIR/eegchannel") ,channel
,@(or prog-and-args (list (ee-expand "$SHELL"))))))
(defun eexterm (channel &optional prog-and-args xterm-args)
"Set the default channel to CHANNEL; create an xterm listening on CHANNEL if needed."
(interactive "sDefault channel: ")
(setq eechannel-default channel)
(if (eechannel-pid-running-p (eechannel-pid channel))
(message "Reusing xterm at channel %s" channel)
(eexterm-create channel prog-and-args xterm-args)))
)
'(
(defun eechannel-running-p (channel)
"Returns t if there is a process listening on CHANNEL."
(let ((pid (eechannel-pid channel)))
(if pid (ee-pid-running-p pid))))
(defun eech (s &optional e) (interactive "r")
(eechannel-send eechannel-default (ee-se-to-string s e)))
(eeb-define 'eech-bounded 'eech 'ee-delimiter-hash nil t t)
(defun eechannel-xterm (channel &optional prog-and-args xterm-args)
"Set the default channel to CHANNEL; create an xterm listening on CHANNEL if needed."
(interactive "sChannel: ")
(eechannel channel)
(if (eechannel-running-p channel)
(message "Reusing channel %s" channel)
(eebg-channel-xterm channel prog-and-args xterm-args)))
(defun eechannel-kill (channel)
"Kill the process associated to channel CHANNEL."
(find-sh0 (format "kill -9 $(cat %s)" (eechannel-pidfile channel))))
)
(provide 'eev-mini-steps)