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

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

Swedish midsummer legends: IPC, collaborative Emacs, sed, awk, DWIM, Uni


From: Emanuel Berg
Subject: Swedish midsummer legends: IPC, collaborative Emacs, sed, awk, DWIM, Unix, and more
Date: Sun, 22 Jun 2014 02:08:38 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Greetings from Sweden where we celebrate midsommar, or
"midsummer"! This will be no news to the Swedes but
truthfully they are painfully absent from anywhere I
go. I have tried very hard to make up for it, and as
long I'm here all our fantastic Danes, Norwegians and
Finns over at Gnus, IRC, and Linux won't take their
shoes off just yet... Midsummer is a pagan festivity
with intoxication and the worship of light. It is
rumored, that those born in those most bright, crisp
summer days, are shamen and wizards! Of course, in such
superstition there is always a grain of
truth. (Tomorrow is my birthday by the way.)

Now, I had to bail out of the discussion on IPC as it
took a hostile tone, which I regret (regrets, I have
but a few). IPC is nonetheless instrumental to
understanding the whole Unix model: the scheduling, the
context switch, and the processes, even the philosophy.

So it happened, I got assigned at work to measure the
time for a single message through a pipe. I put the
investigations here [1], and the result was: 2668
microseconds! Does that sound reasonable? Comments on
the code and mini-tutorial are very appreciated, as
always. Observe, as for now that's not just a bunch of
code written by some Usenet punk showing that what
others can do with a 90-hours work-week and a
seven-digit salary, *he* can do with a keyboard...

As for Emacs, I take it is it just another C binary
with a Lisp REPL on top, so IPC with pipes should be
implementable in the same way. All false modesty put
aside, I can't say I'm capable to write part two of the
tutorial, how IPC mingle with Emacs. But of course,
Emacs can be a batch tool like any other, for example

emacs --batch -l cl --eval '
      (dolist (filename (list $FILES))
         (find-file filename)
         ; do whatever to the file (i.e., to all files)
         (save-buffer)
         (kill-buffer) )'

where it is subject to the conventional Unix piping and
parsing just as sed or awk or whatever (but
interestingly, such use isn't that common, is it?). As
for Emacs as a client, server, daemon, etc., I have no
experience from that but it would be interesting to
hear. Can you send commands to the server, telling it
to do Elisp, and then get a buffer with the results
back?

Last, if the process model explains Unix, the
collaborative scheduling of Emacs was an amazing story,
told to me on this very list. I have thought about that
(actually longer and deeper than a Russian novel) but
still I have failed to come up with any everyday
application to add. But it is a very interesting model
and completely unlike the Unix one, and actually
everything else I heard of, and I suppose it would make
for a great best-effort real-time system which is
nonetheless highly interactive - though again I can't
come up with an real-world application idea...

Dreaming on, I'll share three defuns that I'm the most
happy with lately. Worth checking out:

To make it worthwhile, shortcuts must be used: I have C-a
for back-to-dwin, M-SPC for eat-space, and M-RET for
find-file-at-line. Please share your thoughts :) All
improvements will be instantly effectuated and enjoyed
starting immediately :)

(defun back-to-dwim ()
  (interactive)
  (let ((point (point)))
    (back-to-indentation)
    (if (= point (point))
        (move-beginning-of-line nil) ))) ; nil - same line

(defun eat-space ()
  (interactive "*")
  (let ((start (point))
        (same-line-ws " \t") )
    (beginning-of-line)
    (if (looking-at (format "^[%s]*$" same-line-ws))
        (delete-blank-lines)
      (progn
        (goto-char start)
        (if (= 0 (skip-chars-forward same-line-ws))
            (if (= -1 (skip-chars-backward same-line-ws))
                (delete-horizontal-space)
              (just-one-space) )
          (delete-region start (point)) )))))

(defun find-file-at-line (&optional other-window)
  (interactive "P")
  (let ((possible-filename (thing-at-point 'filename))
        (find-f (if other-window 'find-file-other-window 'find-file)) )
    (if (and possible-filename (file-exists-p possible-filename))
        (progn
          (apply find-f (list possible-filename))
          (silly-window-update) )
      (progn
        (forward-char 1)
        (find-file-at-line) ))))

[1] http://user.it.uu.se/~embe8573/ipc/

-- 
underground experts united:
http://user.it.uu.se/~embe8573


reply via email to

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