help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: shell-CLI for Emacs


From: Emanuel Berg
Subject: Re: shell-CLI for Emacs
Date: Mon, 26 Aug 2013 02:56:35 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux)

Thien-Thi Nguyen <ttn@gnu.org> writes:

> Of course, this technique loses w/ certain (stealthy)
> ‘interactive’ specs ‘interactive’ specs, regions ...

replace-string works with and without a region, when I did exactly
as you told me. But perhaps there is more to regions?

> stateful (history var) defaults

What's that? :)

> args that include a space

I got that solved. Now,

replace-string 'Hello all!' 'Dear all,'

works.

The code [1] got somewhat complicated...

> That's the primary benefit of all DWIM hacking, after all, for
> both you and Emacs!

DWIM, is that what I'm doing? Why did you say that? I'm to read
the Wikipedia article tonight - never heard of it, but intuitively
I like it.

Some people take pride in memorizing and understanding complex
command, drawing oh's and ah's from the crowd: what wizardry! I
think that's just silly. In a nutshell, this is what my system
looks like:

add_dic () { sudo tar -xvjf $1 -C /usr/share/stardict/dic; }

That's why Captain Picard say "Engage!", and not "Set the
thrusters to blaha blaha, align the ship to etc. etc., then..."

(Perhaps that's unrelated to DWIM.)

[1]

(require 'cl)
(defvar *ps* " $> ")

(defun string-to-cmd (str)
  (interactive (list (read-string *ps*)))
  (let*((cmd  (read (car (split-string str " "))))
        (args (cdr (make-arg-list (string-to-list str)))) )
    (dolist (arg (nreverse args))
      (push 13 unread-command-events) ; 13 is RET
      (dolist (n (reverse (string-to-list arg)))
        (push n unread-command-events) ))
    (call-interactively cmd) ))
(define-key (current-global-map) (kbd "M-i") 'string-to-cmd)

(defun make-arg-list (chars)
  (interactive)
  (if chars
      (let ((WS  39) ; whitespace ( )
            (SQM 32) ;      quote (')
            (c  (car chars))
            (cs (cdr chars)) )
        (if (eq c WS) (make-word cs '() WS)
          (if (eq c SQM) (make-arg-list cs)
            (make-word chars '() SQM)) ))
  '() ))

(defun make-word (chars wd sep)
  (interactive)
  (if chars
      (let ((c  (car chars))
            (cs (cdr chars)))
        (if (eq c sep) (cons wd (make-arg-list cs))
          (make-word cs (append wd (list c)) sep)))
    (list wd) ))

-- 
Emanuel Berg - programmer (hire me! CV below)
computer projects: http://user.it.uu.se/~embe8573
internet activity: http://home.student.uu.se/embe8573


reply via email to

[Prev in Thread] Current Thread [Next in Thread]