Klimi's new dotfiles with stow.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

131 regels
5.2 KiB

5 jaren geleden
  1. ;;; helm-id-utils.el --- Helm interface for id-utils. -*- lexical-binding: t -*-
  2. ;; Copyright (C) 2015 ~ 2019 Thierry Volpiatto <thierry.volpiatto@gmail.com>
  3. ;; This program is free software; you can redistribute it and/or modify
  4. ;; it under the terms of the GNU General Public License as published by
  5. ;; the Free Software Foundation, either version 3 of the License, or
  6. ;; (at your option) any later version.
  7. ;; This program is distributed in the hope that it will be useful,
  8. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. ;; GNU General Public License for more details.
  11. ;; You should have received a copy of the GNU General Public License
  12. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ;;; Code:
  14. (require 'helm-grep)
  15. (require 'helm-help)
  16. (defgroup helm-id-utils nil
  17. "ID-Utils related Applications and libraries for Helm."
  18. :group 'helm)
  19. (defcustom helm-gid-program "gid"
  20. "Name of gid command (usually `gid').
  21. For Mac OS X users, if you install GNU coreutils, the name `gid'
  22. might be occupied by `id' from GNU coreutils, and you should set
  23. it to correct name (or absolute path), for example, if using
  24. MacPorts to install id-utils, it should be `gid32'."
  25. :group 'helm-id-utils
  26. :type 'file)
  27. (defcustom helm-gid-db-file-name "ID"
  28. "Name of a database file created by `mkid' command from `ID-utils'."
  29. :group 'helm-id-utils
  30. :type 'string)
  31. (defun helm-gid-candidates-process ()
  32. (let* ((patterns (helm-mm-split-pattern helm-pattern))
  33. (default-com (format "%s -r %s" helm-gid-program
  34. (shell-quote-argument (car patterns))))
  35. (cmd (helm-aif (cdr patterns)
  36. (concat default-com
  37. (cl-loop for p in it
  38. concat (format " | grep --color=always %s"
  39. (shell-quote-argument p))))
  40. default-com))
  41. (proc (start-process-shell-command
  42. "gid" helm-buffer cmd)))
  43. (set (make-local-variable 'helm-grep-last-cmd-line) cmd)
  44. (prog1 proc
  45. (set-process-sentinel
  46. proc (lambda (_process event)
  47. (when (string= event "finished\n")
  48. (helm-maybe-show-help-echo)
  49. (with-helm-window
  50. (setq mode-line-format
  51. '(" " mode-line-buffer-identification " "
  52. (:eval (format "L%s" (helm-candidate-number-at-point))) " "
  53. (:eval (propertize
  54. (format "[Helm Gid process finished - (%s results)]"
  55. (max (1- (count-lines
  56. (point-min) (point-max)))
  57. 0))
  58. 'face 'helm-locate-finish))))
  59. (force-mode-line-update))
  60. (helm-log "Error: Gid %s"
  61. (replace-regexp-in-string "\n" "" event))))))))
  62. (defun helm-gid-filtered-candidate-transformer (candidates _source)
  63. ;; "gid -r" may add dups in some rare cases.
  64. (cl-loop for c in (helm-fast-remove-dups candidates :test 'equal)
  65. collect (helm-grep--filter-candidate-1 c)))
  66. (defclass helm-gid-source (helm-source-async)
  67. ((header-name
  68. :initform
  69. (lambda (name)
  70. (concat name " [" (helm-attr 'db-dir) "]")))
  71. (db-dir :initarg :db-dir
  72. :initform nil
  73. :custom string
  74. :documentation " Location of ID file.")
  75. (candidates-process :initform #'helm-gid-candidates-process)
  76. (filtered-candidate-transformer
  77. :initform #'helm-gid-filtered-candidate-transformer)
  78. (candidate-number-limit :initform 99999)
  79. (action :initform (helm-make-actions
  80. "Find File" 'helm-grep-action
  81. "Find file other frame" 'helm-grep-other-frame
  82. "Save results in grep buffer" 'helm-grep-save-results
  83. "Find file other window" 'helm-grep-other-window))
  84. (persistent-action :initform 'helm-grep-persistent-action)
  85. (history :initform 'helm-grep-history)
  86. (nohighlight :initform t)
  87. (help-message :initform 'helm-grep-help-message)
  88. (requires-pattern :initform 2)))
  89. ;;;###autoload
  90. (defun helm-gid ()
  91. "Preconfigured helm for `gid' command line of `ID-Utils'.
  92. Need A database created with the command `mkid'
  93. above `default-directory'.
  94. Need id-utils as dependency which provide `mkid', `gid' etc...
  95. See <https://www.gnu.org/software/idutils/>."
  96. (interactive)
  97. (let* ((db (locate-dominating-file
  98. default-directory
  99. helm-gid-db-file-name))
  100. (helm-grep-default-directory-fn
  101. (lambda () default-directory))
  102. (helm--maybe-use-default-as-input t))
  103. (cl-assert db nil "No DataBase found, create one with `mkid'")
  104. (helm :sources (helm-make-source "Gid" 'helm-gid-source
  105. :db-dir db)
  106. :buffer "*helm gid*"
  107. :keymap helm-grep-map
  108. :truncate-lines helm-grep-truncate-lines)))
  109. (provide 'helm-id-utils)
  110. ;; Local Variables:
  111. ;; byte-compile-warnings: (not obsolete)
  112. ;; coding: utf-8
  113. ;; indent-tabs-mode: nil
  114. ;; End:
  115. ;;; helm-id-utils ends here