Recently Written · git

tag-gen

Generate tags for each directory and say what programming languages to look for

git clone https://github.com/equwal/tag-gen

Log | Files | Refs


tag-gen.lisp (1918 bytes)

1 ;;;; Generate etags for a list of files.
2 ;;;; Add a command to cron like:
3 ;;;; 0 0 * * * tag-gen ~/.config/tag-gen/tags.conf
4 ;;;;
5 ;;;; tags.conf needs to contain this kind of format:
6 ;;;; (("<directory>" ("<ext>"...))
7 ;;;;   ...)
8 ;;;;
9 ;;;; For example:
10 ;;;; (("/home/jose/.emacs.d" ("el"))
11 ;;;;  ("/home/jose/src/sf/sbcl/sbcl" ("lisp" "c")))
12 ;;;;
13 ;;;; Keep in mind that the home shorthand ~ might not git expanded properly!
14 ;;;;
15 ;;;; For debugging, call with a debug argument 0, 1, 2 where:
16 ;;;; - 0 is silent
17 ;;;; - 1 is for serious errors
18 ;;;; - 2 is for everything
19 
20 (defpackage :tag-gen
21   (:use #:cl #:uiop)
22   (:export #:main))
23 
24 (in-package :tag-gen)
25 
26 (defun add-to-log (msg)
27   (let ((msgstr (format nil "~a" msg)))
28     (format t "~A~@[~%~]"
29             msg
30             (or (zerop (length msgstr))
31                 (char= #\Newline (char msgstr (1- (length msgstr))))))))
32 
33 (defun tag-gen (tags tag-program)
34   (labels ((extensions (dir exts)
35              (when exts
36                (and tags (add-to-log (car tags)))
37                (add-to-log
38                 (or (and (not (directory-exists-p dir))
39                          (cons (format nil "The directory ~A doesn't exist" dir) 1))
40                     (run-program (format nil "find ~A -type f -iname \"*.~A\" | ~A -"
41                                                dir
42                                                (car exts)
43                                                tag-program)
44                                        :ignore-error-status t
45                                        :output '(string :stripped t))))
46                (extensions dir (cdr exts)))))
47     (when tags
48       (extensions (caar tags) (cadar tags))
49       (tag-gen (cdr tags) tag-program))))
50 
51 (defun main (conf &rest argv)
52   (declare (ignorable argv))
53   (with-open-file (s conf :direction :input)
54     (let ((tag-program (read s)))
55       (tag-gen (read s) (unix-namestring tag-program)))))