Skip to content

Instantly share code, notes, and snippets.

@johnmastro
Created August 12, 2015 01:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnmastro/501da21cff5deb9165a5 to your computer and use it in GitHub Desktop.
Save johnmastro/501da21cff5deb9165a5 to your computer and use it in GitHub Desktop.
Kludge for projectile-regenerate-tags on Windows+Cygwin
(defun maybe-cygwinize-drive-letter (file)
"Return FILE in a Cygwin-friendly format.
For example, given \"c:/foo/bar\" return \"/foo/bar\", or given
\"e:/foo/bar\" return \"/e/foo/bar\"."
(cond ((string-match "\\`[Cc]:/" file)
(replace-match "/" t t file))
((string-match "\\`\\([A-Za-z]\\):/" file)
(replace-match (concat "/" (match-string 1 file) "/")
t t file))
(t file)))
(defun my-projectile-regenerate-tags ()
"Patched version of `projectile-regenerate-tags' for use on Cygwin.
Identical to the original `projectile-regenerate-tags' (at the
time I copied it) except for the call to
`maybe-cygwinize-drive-letter'."
(interactive)
(let* ((project-root (projectile-project-root))
(tags-exclude (projectile-tags-exclude-patterns))
(default-directory project-root)
(tags-file (expand-file-name projectile-tags-file-name))
;; Make `tags-file' into something the Cygwin ctags.exe can work with
(tags-file (maybe-cygwinize-drive-letter tags-file))
(command (format projectile-tags-command tags-file tags-exclude))
shell-output exit-code)
(with-temp-buffer
(setq exit-code
(call-process-shell-command command nil (current-buffer))
shell-output (projectile-trim-string
(buffer-substring (point-min) (point-max)))))
(unless (zerop exit-code)
(error shell-output))
(visit-tags-table tags-file)))
(with-eval-after-load 'projectile
(when (eq system-type 'windows-nt)
(fset 'projectile-regenerate-tags #'my-projectile-regenerate-tags)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment