Guest User

Search In Project LW Editor Command

a guest
Dec 30th, 2023
700
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 1.52 KB | Software | 0 0
  1. (defpackage #:lw-config.editor-commands
  2.   (:use #:cl #:editor)
  3.   (:add-use-defaults t))
  4.  
  5. (in-package lw-config.editor-commands)
  6.  
  7. (defun file-present-p (dirname filename)
  8.   "Detect if the file FILENAME present in the directory DIRNAME"
  9.   (not (null
  10.         (fast-directory-files
  11.          dirname
  12.          (lambda (name fdf-hndl)
  13.            (declare (ignore fdf-hndl))
  14.            (string= name filename))))))
  15.  
  16. (defun get-current-buffer-filename ()
  17.   (buffer-pathname (current-buffer)))
  18.  
  19. (defun get-project-root (&optional (filename (get-current-buffer-filename)))
  20.   "By give absolute file name, search for the .git directory
  21. traversing up the directory tree."
  22.   (loop for dir = (pathname-directory filename) then (butlast dir)
  23.         for pdir = (make-pathname :directory dir)
  24.         for found = (file-present-p pdir ".git")
  25.         until (or found
  26.                   (= (length dir) 1)) ;; always include :absolute in list
  27.         finally (return (and found pdir))))
  28.  
  29. (defcommand "Search In Project" (p &optional (string
  30.                                               (symbol-name (buffer-symbol-at-point
  31.                                                (current-buffer)))))
  32.      "Search for STRING in current project"
  33.      "Start a Search tool"
  34.   (let ((root (get-project-root)))
  35.     (editor::call-make-directory-search :root-directory root
  36.                                         :string string
  37.                                         :patterns "**/*.lisp"
  38.                                         :start-p (if p nil t))))
Tags: lispworks
Advertisement
Add Comment
Please, Sign In to add comment