branch: elpa/magit commit 56197d8a40615f523a77dd260005f0a009a344c6 Author: Jonas Bernoulli <jo...@bernoul.li> Commit: Jonas Bernoulli <jo...@bernoul.li>
magit-dired.el: New library --- default.mk | 1 + lisp/Makefile | 1 + lisp/magit-diff.el | 2 +- lisp/magit-dired.el | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++ lisp/magit-extras.el | 58 ------------------------------- lisp/magit.el | 1 + 6 files changed, 102 insertions(+), 59 deletions(-) diff --git a/default.mk b/default.mk index fa21db8611..f23c2fbaf7 100644 --- a/default.mk +++ b/default.mk @@ -101,6 +101,7 @@ ELS += magit-ediff.el ELS += magit-gitignore.el ELS += magit-bundle.el ELS += magit-extras.el +ELS += magit-dired.el ELS += git-rebase.el ELS += magit-bookmark.el ELCS = $(ELS:.el=.elc) diff --git a/lisp/Makefile b/lisp/Makefile index dcd3b193c9..313b89834c 100644 --- a/lisp/Makefile +++ b/lisp/Makefile @@ -56,6 +56,7 @@ magit-gitignore.elc: magit.elc magit-sparse-checkout.elc: magit.elc magit-bundle.elc: magit.elc magit-extras.elc: magit.elc magit-merge.elc +magit-dired.elc: magit.elc git-rebase.elc: magit.elc magit-bookmark.elc: magit.elc diff --git a/lisp/magit-diff.el b/lisp/magit-diff.el index a5444d23c5..3f4f6055cb 100644 --- a/lisp/magit-diff.el +++ b/lisp/magit-diff.el @@ -73,7 +73,7 @@ (declare-function magit-commit-add-log "magit-commit" ()) (declare-function magit-diff-trace-definition "magit-log" ()) (declare-function magit-patch-save "magit-patch" (files &optional arg)) -(declare-function magit-do-async-shell-command "magit-extras" (file)) +(declare-function magit-do-async-shell-command "magit-dired" (file)) (declare-function magit-add-change-log-entry "magit-extras" (&optional whoami file-name other-window)) (declare-function magit-add-change-log-entry-other-window "magit-extras" diff --git a/lisp/magit-dired.el b/lisp/magit-dired.el new file mode 100644 index 0000000000..084ccd58a0 --- /dev/null +++ b/lisp/magit-dired.el @@ -0,0 +1,98 @@ +;;; magit-dired.el --- Dired support for Magit -*- lexical-binding:t -*- + +;; Copyright (C) 2008-2025 The Magit Project Contributors + +;; Author: Jonas Bernoulli <emacs.ma...@jonas.bernoulli.dev> +;; Maintainer: Jonas Bernoulli <emacs.ma...@jonas.bernoulli.dev> + +;; SPDX-License-Identifier: GPL-3.0-or-later + +;; Magit is free software: you can redistribute it and/or modify it +;; under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. +;; +;; Magit is distributed in the hope that it will be useful, but WITHOUT +;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +;; License for more details. +;; +;; You should have received a copy of the GNU General Public License +;; along with Magit. If not, see <https://www.gnu.org/licenses/>. + +;;; Commentary: + +;; Dired support for Magit. + +;;; Code: + +(require 'magit) + +;; For `magit-do-async-shell-command'. +(declare-function dired-read-shell-command "dired-aux" (prompt arg files)) + +;;; Open Dired from Magit + +;;;###autoload +(defun magit-dired-jump (&optional other-window) + "Visit file at point using Dired. +With a prefix argument, visit in another window. If there +is no file at point, then instead visit `default-directory'." + (interactive "P") + (dired-jump other-window + (and-let* ((file (magit-file-at-point))) + (expand-file-name (if (file-directory-p file) + (file-name-as-directory file) + file))))) + +;;; Commands for Dired Buffers + +;;;###autoload +(defun magit-dired-log (&optional follow) + "Show log for all marked files, or the current file." + (interactive "P") + (if-let ((topdir (magit-toplevel default-directory))) + (let ((args (car (magit-log-arguments))) + (files (dired-get-marked-files nil nil #'magit-file-tracked-p))) + (unless files + (user-error "No marked file is being tracked by Git")) + (when (and follow + (not (member "--follow" args)) + (not (cdr files))) + (push "--follow" args)) + (magit-log-setup-buffer + (list (or (magit-get-current-branch) "HEAD")) + args + (let ((default-directory topdir)) + (mapcar #'file-relative-name files)) + magit-log-buffer-file-locked)) + (magit--not-inside-repository-error))) + +;;;###autoload +(defun magit-dired-am-apply-patches (repo &optional arg) + "In Dired, apply the marked (or next ARG) files as patches. +If inside a repository, then apply in that. Otherwise prompt +for a repository." + (interactive (list (or (magit-toplevel) + (magit-read-repository t)) + current-prefix-arg)) + (let ((files (dired-get-marked-files nil arg nil nil t))) + (magit-status-setup-buffer repo) + (magit-am-apply-patches files))) + +;;; Miscellaneous Commands + +;;;###autoload +(defun magit-do-async-shell-command (file) + "Open FILE with `dired-do-async-shell-command'. +Interactively, open the file at point." + (interactive (list (or (magit-file-at-point) + (magit-read-file "Act on file")))) + (require 'dired-aux) + (dired-do-async-shell-command + (dired-read-shell-command "& on %s: " current-prefix-arg (list file)) + nil (list file))) + +;;; _ +(provide 'magit-dired) +;;; magit-dired.el ends here diff --git a/lisp/magit-extras.el b/lisp/magit-extras.el index 63264584dc..7e346a689a 100644 --- a/lisp/magit-extras.el +++ b/lisp/magit-extras.el @@ -28,8 +28,6 @@ (require 'magit) -;; For `magit-do-async-shell-command'. -(declare-function dired-read-shell-command "dired-aux" (prompt arg files)) ;; For `magit-project-status'. (declare-function vc-git-command "vc-git" (buffer okstatus file-or-list &rest flags)) @@ -217,62 +215,6 @@ to nil before loading Magit to prevent \"m\" from being bound.") (keymap-set project-prefix-map "m" #'magit-project-status) (add-to-list 'project-switch-commands '(magit-project-status "Magit") t))) -;;;###autoload -(defun magit-dired-jump (&optional other-window) - "Visit file at point using Dired. -With a prefix argument, visit in another window. If there -is no file at point, then instead visit `default-directory'." - (interactive "P") - (dired-jump other-window - (and-let* ((file (magit-file-at-point))) - (expand-file-name (if (file-directory-p file) - (file-name-as-directory file) - file))))) - -;;;###autoload -(defun magit-dired-log (&optional follow) - "Show log for all marked files, or the current file." - (interactive "P") - (if-let ((topdir (magit-toplevel default-directory))) - (let ((args (car (magit-log-arguments))) - (files (dired-get-marked-files nil nil #'magit-file-tracked-p))) - (unless files - (user-error "No marked file is being tracked by Git")) - (when (and follow - (not (member "--follow" args)) - (not (cdr files))) - (push "--follow" args)) - (magit-log-setup-buffer - (list (or (magit-get-current-branch) "HEAD")) - args - (let ((default-directory topdir)) - (mapcar #'file-relative-name files)) - magit-log-buffer-file-locked)) - (magit--not-inside-repository-error))) - -;;;###autoload -(defun magit-dired-am-apply-patches (repo &optional arg) - "In Dired, apply the marked (or next ARG) files as patches. -If inside a repository, then apply in that. Otherwise prompt -for a repository." - (interactive (list (or (magit-toplevel) - (magit-read-repository t)) - current-prefix-arg)) - (let ((files (dired-get-marked-files nil arg nil nil t))) - (magit-status-setup-buffer repo) - (magit-am-apply-patches files))) - -;;;###autoload -(defun magit-do-async-shell-command (file) - "Open FILE with `dired-do-async-shell-command'. -Interactively, open the file at point." - (interactive (list (or (magit-file-at-point) - (magit-read-file "Act on file")))) - (require 'dired-aux) - (dired-do-async-shell-command - (dired-read-shell-command "& on %s: " current-prefix-arg (list file)) - nil (list file))) - ;;; Shift Selection (defun magit--turn-on-shift-select-mode-p () diff --git a/lisp/magit.el b/lisp/magit.el index b240b9436a..d26faf60ab 100644 --- a/lisp/magit.el +++ b/lisp/magit.el @@ -782,6 +782,7 @@ For X11 something like ~/.xinitrc should work.\n" (require 'magit-gitignore) (require 'magit-sparse-checkout) (require 'magit-extras) + (require 'magit-dired) (require 'git-rebase) (require 'magit-bookmark)))