From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Emanuel Berg via help-gnu-emacs Newsgroups: gmane.emacs.help Subject: Re: Is Elisp really that slow? Date: Thu, 30 May 2019 14:09:05 +0200 Message-ID: <86r28g400u.fsf@zoho.eu> References: <20190515210924.sijzy6mnpgzkt4gm@Ergus> <83ftpecwu1.fsf@gnu.org> <20190516161408.4dov3dwk5h4yoizn@Ergus> <838sv6cmwt.fsf@gnu.org> <20190516202327.5cgy2s4kppy3ahxa@Ergus> <871s0yqg2i.fsf@telefonica.net> <3210C8E9-7A74-47D6-81A0-470948E6D09C@gmail.com> <87r28xq0j1.fsf@telefonica.net> <5495188F-7A7D-4E50-82C4-E2CBABD8633D@gmail.com> <20190517060858.xoddgzyudvo4p2oo@Ergus> <20190517092120.GE9018@tuxteam.de> <87imu9p4c1.fsf@telefonica.net> Reply-To: Emanuel Berg Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="255474"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu May 30 14:09:39 2019 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hWJsJ-0014H4-35 for geh-help-gnu-emacs@m.gmane.org; Thu, 30 May 2019 14:09:39 +0200 Original-Received: from localhost ([127.0.0.1]:53209 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hWJsI-0000Ns-1X for geh-help-gnu-emacs@m.gmane.org; Thu, 30 May 2019 08:09:38 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:53002) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hWJrz-0000MP-Sb for help-gnu-emacs@gnu.org; Thu, 30 May 2019 08:09:21 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hWJrw-000780-Rj for help-gnu-emacs@gnu.org; Thu, 30 May 2019 08:09:19 -0400 Original-Received: from [195.159.176.226] (port=38574 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hWJrw-0006tL-Kc for help-gnu-emacs@gnu.org; Thu, 30 May 2019 08:09:16 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.89) (envelope-from ) id 1hWJrr-0013kd-LT for help-gnu-emacs@gnu.org; Thu, 30 May 2019 14:09:11 +0200 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: help-gnu-emacs@gnu.org Mail-Copies-To: never Cancel-Lock: sha1:p7268SvXMTZaoc5bqMz4GgpvVCg= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 195.159.176.226 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:120697 Archived-At: 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." (interactive) (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) (interactive `(,(read-from-minibuffer "regexp: ") ,(read-from-minibuffer "replace: ") ,@(if (use-region-p) (list (region-beginning) (region-end)) (list (point-min) (point-max))) )) (save-excursion (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 phenomena... [1] line 64 @ https://dataswamp.org/~incal/emacs-init/edit.el [2] https://dataswamp.org/~incal/emacs-init/sudo-user-path.el [3] line 8, same URL as in [1] -- underground experts united http://user.it.uu.se/~embe8573 https://dataswamp.org/~incal