103 lines
4.1 KiB
EmacsLisp
103 lines
4.1 KiB
EmacsLisp
|
;;; funcs.el --- Spacemacs Project Management Layer packages File
|
|||
|
;;
|
|||
|
;; Copyright (c) 2012-2018 Sylvain Benner & Contributors
|
|||
|
;;
|
|||
|
;; Author: Codruț Constantin Gușoi <codrut.gusoi@gmail.com>
|
|||
|
;; URL: https://github.com/syl20bnr/spacemacs
|
|||
|
;;
|
|||
|
;; This file is not part of GNU Emacs.
|
|||
|
;;
|
|||
|
;;; License: GPLv3
|
|||
|
|
|||
|
(defun spacemacs--projectile-directory-path ()
|
|||
|
"Retrieve the directory path relative to project root.
|
|||
|
|
|||
|
If the buffer is not visiting a file, use the `list-buffers-directory'
|
|||
|
variable as a fallback to display the directory, useful in buffers like the
|
|||
|
ones created by `magit' and `dired'.
|
|||
|
|
|||
|
Returns:
|
|||
|
- A string containing the directory path in case of success.
|
|||
|
- `nil' in case the current buffer does not have a directory."
|
|||
|
(when-let (directory-name (if-let (file-name (buffer-file-name))
|
|||
|
(file-name-directory file-name)
|
|||
|
list-buffers-directory))
|
|||
|
(file-relative-name
|
|||
|
(file-truename directory-name)
|
|||
|
(projectile-project-root))))
|
|||
|
|
|||
|
(defun spacemacs--projectile-file-path ()
|
|||
|
"Retrieve the file path relative to project root.
|
|||
|
|
|||
|
Returns:
|
|||
|
- A string containing the file path in case of success.
|
|||
|
- `nil' in case the current buffer does not visit a file."
|
|||
|
(when-let (file-name (buffer-file-name))
|
|||
|
(file-relative-name (file-truename file-name) (projectile-project-root))))
|
|||
|
|
|||
|
(defun spacemacs--projectile-file-path-with-line ()
|
|||
|
"Retrieve the file path relative to project root, including line number.
|
|||
|
|
|||
|
Returns:
|
|||
|
- A string containing the file path in case of success.
|
|||
|
- `nil' in case the current buffer does not visit a file."
|
|||
|
(when-let (file-path (spacemacs--projectile-file-path))
|
|||
|
(concat file-path ":" (number-to-string (line-number-at-pos)))))
|
|||
|
|
|||
|
(defun spacemacs--projectile-file-path-with-line-column ()
|
|||
|
"Retrieve the file path relative to project root, including line and column number.
|
|||
|
|
|||
|
This function respects the value of the `column-number-indicator-zero-based'
|
|||
|
variable.
|
|||
|
|
|||
|
Returns:
|
|||
|
- A string containing the file path in case of success.
|
|||
|
- `nil' in case the current buffer does not visit a file."
|
|||
|
(when-let (file-path (spacemacs--projectile-file-path-with-line))
|
|||
|
(concat
|
|||
|
file-path
|
|||
|
":"
|
|||
|
(number-to-string (if (and
|
|||
|
;; Emacs 26 introduced this variable.
|
|||
|
;; Remove this check once 26 becomes the minimum version.
|
|||
|
(boundp column-number-indicator-zero-based)
|
|||
|
(not column-number-indicator-zero-based))
|
|||
|
(1+ (current-column))
|
|||
|
(current-column))))))
|
|||
|
|
|||
|
|
|||
|
(defun spacemacs/projectile-copy-directory-path ()
|
|||
|
"Copy and show the directory path relative to project root.
|
|||
|
|
|||
|
If the buffer is not visiting a file, use the `list-buffers-directory'
|
|||
|
variable as a fallback to display the directory, useful in buffers like the
|
|||
|
ones created by `magit' and `dired'."
|
|||
|
(interactive)
|
|||
|
(if-let (directory-path (spacemacs--projectile-directory-path))
|
|||
|
(message "%s" (kill-new directory-path))
|
|||
|
(message "WARNING: Current buffer does not have a directory!")))
|
|||
|
|
|||
|
(defun spacemacs/projectile-copy-file-path ()
|
|||
|
"Copy and show the file path relative to project root."
|
|||
|
(interactive)
|
|||
|
(if-let (file-path (spacemacs--projectile-file-path))
|
|||
|
(message "%s" (kill-new file-path))
|
|||
|
(message "WARNING: Current buffer is not visiting a file!")))
|
|||
|
|
|||
|
(defun spacemacs/projectile-copy-file-path-with-line ()
|
|||
|
"Copy and show the file path relative to project root, including line number."
|
|||
|
(interactive)
|
|||
|
(if-let (file-path (spacemacs--projectile-file-path-with-line))
|
|||
|
(message "%s" (kill-new file-path))
|
|||
|
(message "WARNING: Current buffer is not visiting a file!")))
|
|||
|
|
|||
|
(defun spacemacs/projectile-copy-file-path-with-line-column ()
|
|||
|
"Copy and show the file path relative to project root, including line and column number.
|
|||
|
|
|||
|
This function respects the value of the `column-number-indicator-zero-based'
|
|||
|
variable."
|
|||
|
(interactive)
|
|||
|
(if-let (file-path (spacemacs--projectile-file-path-with-line-column))
|
|||
|
(message "%s" (kill-new file-path))
|
|||
|
(message "WARNING: Current buffer is not visiting a file!")))
|