[Top][All Lists]

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

Re: Is Elisp really that slow?

From: Emanuel Berg
Subject: Re: Is Elisp really that slow?
Date: Thu, 30 May 2019 14:09:05 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux)

Re: Is Elisp really that slow?
Óscar Fuentes wrote:

> (In my experience, the possibility that
> better things could exist don't cross the
> mind of many users.)

But finding things in Emacs isn't always
so easy. Often I get a feeling, either this
exists already or how come in hell I'm the first
person to think of such a basic thing?

I know about the on-line help (on-line = not on
paper :)), about `info', about `apropos' with
`apropos-command' and `apropos-value' and
all that. Still, when you are in the workflow,
and you don't want to leave it to find the real
deal (which you think, but cannot _know_
already exists) you just write Elisp yourself.

Here are two examples. This one I wrote as
a pretty novice Lisper:

(require 'dired)
(defun su-edit ()
  "Edit the current buffer file as superuser."
  (let*((window-start (window-start))
        (point        (point))
        (mark         (when mark-active (mark)))
        (path         (or dired-directory
                          (file-truename (buffer-file-name)) ))
        (sudo-path    (sudo-root-path path)) )
    (find-alternate-file sudo-path)
    (when mark (set-mark mark))
    (goto-char point)
    (when dired-directory (dired-previous-line 1))
    (set-window-start nil window-start) ; the selected WINDOW
    )) ; [1]

The `sudo-root-path path' is here: [2]

This OTOH I wrote just this week or so:

(defun case-sensitive-regexp-search-and-replace (regexp to-string &optional 
start stop)
   `(,(read-from-minibuffer "regexp: ")
     ,(read-from-minibuffer "replace: ")
     ,@(if (use-region-p) (list (region-beginning) (region-end))
         (list (point-min) (point-max))) ))
    (let ((beg (or start (point-min)))
          (end (or stop  (point-max))) )
      (goto-char beg)
      (let ((case-fold-search nil))
        (while (re-search-forward regexp end t)
          (replace-match to-string t) )))))
(defalias 'cs-replace #'case-sensitive-regexp-search-and-replace) ; [3]

In both "cases" ... :) ... I'm pretty sure
there are canonical ways to do both because
they would seem so fundamental.

As for the quality of the code and possible
bugs, actually I'm more confident with
"su-edit" because I used that so many times,
despite the code doesn't really look good,
than with "cs-replace", having used that only
a few couple of times thus far. But as always,
suggestions/corrections are welcome, even when
the code serves to illustrate a detached

[1] line 64 @
[3] line 8, same URL as in [1]

underground experts united

reply via email to

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