emacs-devel
[Top][All Lists]
Advanced

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

Re: find-file-dwim.el


From: Emanuel Berg
Subject: Re: find-file-dwim.el
Date: Mon, 22 Jul 2024 07:32:15 +0200
User-agent: Gnus/5.13 (Gnus v5.13)

> I'll do the legendary Holy Grail of Elisp programming,
> namely find-file-dwim.el

Four methods now and one can add a lot of those if one comes up
with new ideas.

What remains to do, well, polishing, is the interface and
I think it will be super-important to get that right, how to
indicate a suggested file isn't what you look for, for
example.

I'll post a new version in a couple of days or so, maybe.

;;; -*- lexical-binding: t -*-
;;
;; this file:
;;   https://dataswamp.org/~incal/emacs-init/find-file-dwim.el
;;
;; created: 2024-07-22
;; version: 0.1.0

(require 'cl-lib)
(require 'psea)   ; https://dataswamp.org/~incal/emacs-init/psea.el

(defun buffers ()
  (mapcar #'buffer-name (buffer-list)) )

;; (buffers)

(defun mod-time-sec (f)
  (let ((s (time-convert
              (file-attribute-modification-time (file-attributes f))
            'integer) ))
    (list s f) ))

;; (mod-time-sec "~/.emacs")

(defun remove-data (ds)
  (mapcar #'cadr ds) )

(defun sort-mod-time-sec (&optional dir)
  (or dir (setq dir default-directory))
  (let ((fs (directory-files dir nil nil t)))
    (remove-data
      (reverse (cl-sort (mapcar #'mod-time-sec fs) #'> :key #'car)) )))

;; (sort-mod-time-sec)

(defun psea-hit (s fs &optional max gov)
  (and max (setq fs (seq-take fs max)))
  (or  gov (setq gov 70) )
  (cl-loop
    with perc
    with res
    for f in fs do
      (setq perc (sdp s f))
      (when (< gov perc)
        (cl-pushnew (list perc f) res) )
    finally return (remove-data (cl-sort res #'> :key #'car)) ))

;; (psea-hit "buffer-menu"       (buffers))
;; (psea-hit "find-file-dwim.el" (sort-mod-time-sec))

(defun re-hit (re fs &optional max)
  (and max (setq fs (seq-take fs max)))
  (cl-remove-if-not (lambda (f) (string-match re f)) fs) )

;; (re-hit "line" (buffers))
;; (re-hit "line" (sort-mod-time-sec) 1000)

(provide 'find-file-dwim)

-- 
underground experts united
https://dataswamp.org/~incal




reply via email to

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