all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Swedish midsummer legends: IPC, collaborative Emacs, sed, awk, DWIM, Unix, and more
@ 2014-06-22  0:08 Emanuel Berg
  2014-06-22 23:54 ` Robert Thorpe
  0 siblings, 1 reply; 2+ messages in thread
From: Emanuel Berg @ 2014-06-22  0:08 UTC (permalink / raw)
  To: help-gnu-emacs

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Swedish midsummer legends: IPC, collaborative Emacs, sed, awk, DWIM, Unix, and more
  2014-06-22  0:08 Swedish midsummer legends: IPC, collaborative Emacs, sed, awk, DWIM, Unix, and more Emanuel Berg
@ 2014-06-22 23:54 ` Robert Thorpe
  0 siblings, 0 replies; 2+ messages in thread
From: Robert Thorpe @ 2014-06-22 23:54 UTC (permalink / raw)
  To: Emanuel Berg; +Cc: help-gnu-emacs

Emanuel Berg <embe8573@student.uu.se> writes:

> 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?

Of-course, see "Invoking Emacsclient" in the Emacs info manual.  The
startup-time of the way you're doing it is likely to be long.  Programs
like sed & awk are much smaller and simpler, they don't suffer from that
problem.  It's quite possible to write text-processing scripts in Elisp
this way, I've done it myself.  Now there are good scripting languages
few people do it though.

The rest of your message has some useful stuff in it.  It's is rather
like a blog post.  Have you thought of writing a blog on Emacs and
putting in stuff like this?

BR,
Robert Thorpe



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-06-22 23:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-22  0:08 Swedish midsummer legends: IPC, collaborative Emacs, sed, awk, DWIM, Unix, and more Emanuel Berg
2014-06-22 23:54 ` Robert Thorpe

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.