unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Arthur Miller <arthur.miller@live.com>
To: Dmitry Gutov <dgutov@yandex.ru>
Cc: "Emacs developers" <emacs-devel@gnu.org>,
	me@wilfred.me.uk, "Stefan Kangas" <stefan@marxist.se>,
	"Daniel Martín" <mardani29@yahoo.es>
Subject: Re: Helpful in Emacs?
Date: Fri, 10 Sep 2021 02:52:25 +0200	[thread overview]
Message-ID: <AM9PR09MB4977169C98AB453B808B9A3C96D69@AM9PR09MB4977.eurprd09.prod.outlook.com> (raw)
In-Reply-To: <bcd43415-863d-4602-d407-ac6b7e74399f@yandex.ru> (Dmitry Gutov's message of "Fri, 10 Sep 2021 01:55:08 +0300")

[-- Attachment #1: Type: text/plain, Size: 2742 bytes --]

Dmitry Gutov <dgutov@yandex.ru> writes:

> On 09.09.2021 23:23, Arthur Miller wrote:
>> What do you need to build  xref backend you mention? As mentioned on elisp-refs
>> gh page:
>> "xref-find-references: This command is included in Emacs 25.1, but it's based
>> on
>> a text search. It is confused by comments and strings, and cannot distinguish
>> between functions and variables."
>> Would rebuilding this command to use read instead of text search do the thing?
>
> You can easily plug another search implementation in xref-find-references. You
> can even make summaries multiline (though that would feel weird to me).
Ok, that sounds good.

> But is elisp-refs that much better at searching? Distinguishing variables from
> functions sounds nice, but then you might want to rename the function -- and
> you'll probably want to rename the variable with the same name as well.

I can't really tell you since I am not an expert. The quote was from the
elisp-refs project. Read does have semantic information about symbols readily
avialable, plain string searching does not have it immidiately, but strings can
always be interned and looked up, so I really don't know how it compares to
xref. I do believe that the author is correct in what it says, otherwise I don't
think he would be doing that work. Observe also that the comment is old, a
couple of years or more.

> Same about comments: if elisp-refs skips comments altogether (rather than
> smartly parsing references inside), you might miss some references to your
> function when doing a rename.

> I also wonder how it compares in performance.

I haven't benchmarked or done any deeper investigations; I haven't even had time
to look at his code yet; but I don't think the performance would be much
different than just search through buffer. Read might be somewhat faster since
it isn't as general regex matcher as regex-search is I guess, but that would be
just my wild guessing, I don't think I am qualified to speak much about
performance here without benchmarking.

However what I have experienced, in my own little experiment, is that searching for
all symbol definitions in entire Emacs lisp directory went fast on my computer,
~2 seconds, with flushing the database to the disk. Now I don't do much, I just
collect all defuns, defmacros, defvars and defcustoms, so it is not terribly
lots of work, finding references is probably much more work, but at least as an
experiment it indicates that it could be very fast. I attached the code for the
reference.

(benchmark-run (ff-build-emacs-db))

(2.037053179 0 0.0)

Now I don't know how fast is xref-find-references nor how it does what it does
yet either, so lots here is just speculations, most of them probably wrong :). 


[-- Attachment #2: func-freq.el --]
[-- Type: text/plain, Size: 3258 bytes --]

;;; func-freq.el ---                                 -*- lexical-binding: t; -*-

;; Copyright (C) 2021  Arthur Miller

;; Author: Arthur Miller <arthur.miller@live.com>
;; Keywords: 

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <https://www.gnu.org/licenses/>.

;;; Commentary:

;; 

;;; Code:
(defun ff-print (map)
  (maphash (lambda (k v) (print (format "%s: %s" k v))) map))

(defvar ff-srcs nil
  "Cash list of source files.")
(defvar ff-lmap nil
  "Load paths")
(defvar ff-pmap nil
  "Provided features")
(defvar ff-vmap nil
  "Variables")
(defvar ff-fmap nil
  "Functions and macros")

(defun ff-save-db (db-file)
  (with-temp-file db-file
    (prin1 ff-lmap (current-buffer))
    (prin1 ff-pmap (current-buffer))
    (prin1 ff-vmap (current-buffer))
    (prin1 ff-fmap (current-buffer))))

(defun ff-read-db (db-file)
  (with-temp-buffer
    (insert-file-contents db-file)
    (goto-char (point-min))
    (setq ff-lmap (read (current-buffer))
          ff-pmap (read (current-buffer))
          ff-vmap (read (current-buffer))
          ff-fmap (read (current-buffer)))))

(defun ff-collect-features (src index)
  (let (sxp)
    (with-current-buffer (get-buffer-create "*ff-buffer*")
      (erase-buffer)
      (insert-file-contents src)
      (goto-char (point-min))
      (while (setq sxp (ignore-errors (read (current-buffer))))
        (when (listp sxp)
          (cond ((or (equal (car sxp) 'defun)
                     (equal (car sxp) 'defmacro))
                 (puthash (cadr sxp) index ff-fmap))
                ((or (equal (car sxp) 'defvar)
                     (equal (car sxp) 'defcustom))
                 (puthash (cadr sxp) index ff-vmap))
                ((equal (car sxp) 'provide)
                 (puthash (cadr sxp) index ff-pmap))))))))

(defun ff-build-db (dir-tree)
  ;;(when (or (not ff-srcs) (equal (car ff-srcs) dir-tree))
      (setq ff-srcs (cons dir-tree (directory-files-recursively dir-tree "\\.el$"))
            ff-lmap (make-hash-table :test 'equal)
            ff-vmap (make-hash-table :test 'equal)
            ff-fmap (make-hash-table :test 'equal)
            ff-pmap (make-hash-table :test 'equal))
      ;; )
  (let ((index 0))
    (dolist (src (cdr ff-srcs))
      (puthash index src ff-lmap)
      (ff-collect-features src index)
      (setq index (1+ index)))))

(defun ff-build-emacs-db ()
  (ff-build-db (expand-file-name "lisp/" source-directory))
  (ff-save-db (expand-file-name "ff-db-emacs" user-emacs-directory)))

(defun ff-build-package-db ()
  (ff-build-db (expand-file-name "elpa/" user-emacs-directory))
  (ff-save-db (expand-file-name "ff-db-packages" user-emacs-directory)))

(provide 'func-freq)
;;; func-freq.el ends here

  reply	other threads:[~2021-09-10  0:52 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-09 10:57 Helpful in Emacs? Arthur Miller
2021-09-09 11:34 ` Stefan Kangas
2021-09-09 12:35   ` Arthur Miller
2021-09-09 15:21     ` Daniel Martín
2021-09-09 15:48       ` Arthur Miller
2021-09-10  6:20         ` Stefan Kangas
2021-09-10  7:11           ` Arthur Miller
2021-09-10  7:19             ` Stefan Kangas
2021-09-10  7:58               ` Arthur Miller
2021-09-10  8:14                 ` Jean-Christophe Helary
2021-09-10 12:32               ` Stefan Monnier
2021-09-10  7:26             ` Eli Zaretskii
2021-09-10  8:00               ` Arthur Miller
2021-09-10 11:14                 ` Eli Zaretskii
2021-09-10 11:41                   ` Arthur Miller
2021-09-09 19:21       ` Eduardo Ochs
2021-09-09 19:51         ` Arthur Miller
2021-09-09 20:23       ` Arthur Miller
2021-09-09 22:55         ` Dmitry Gutov
2021-09-10  0:52           ` Arthur Miller [this message]
2021-09-10  6:16           ` Eli Zaretskii
2021-09-10  6:06         ` Eli Zaretskii
2021-09-10  6:21           ` Arthur Miller
2021-09-10  6:30       ` Juri Linkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=AM9PR09MB4977169C98AB453B808B9A3C96D69@AM9PR09MB4977.eurprd09.prod.outlook.com \
    --to=arthur.miller@live.com \
    --cc=dgutov@yandex.ru \
    --cc=emacs-devel@gnu.org \
    --cc=mardani29@yahoo.es \
    --cc=me@wilfred.me.uk \
    --cc=stefan@marxist.se \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).