branch: elpa/crux commit 6ee63c7c2b64a8ecf5bba48c2d62b14a87bb76da Author: Michael Eliachevitch <m.eliachevi...@posteo.de> Commit: GitHub <nore...@github.com>
Use `derived-mode-p` for functions to also work for derived modes (#92) In my case I recently started using `dirvish', which is an enhanced dired-mode, and I was surprised that `crux-open-with' didn't work, but I fixed it by using `derived-mode-p'. Then, I searched for other occurances of `major-mode' and also replaced (equal major-mode '<mode>) by (derived-mode-p '<mode>) I'm still not sure whether I should also do that in `crux-cleanup-buffer-or-region', where in checking the membership in `crux-untabify-sensitive-modes' and `crux-indent-sensitive-modes', derived modes are not considered. So far I didn't touch that, since those variables are customizable anyway. --- CHANGELOG.md | 1 + crux.el | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae9b99d136..518ed8a3c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ ### New features +* [#92](https://github.com/bbatsov/crux/pull/92): Consider derived modes when checking for major mode (dired, org-mode, eshell) * [#65](https://github.com/bbatsov/crux/pull/65): Add a configuration option to move using visual lines in `crux-move-to-mode-line-start`. * [#72](https://github.com/bbatsov/crux/pull/72): Add `crux-kill-buffer-truename`. Kills path of file visited by current buffer. * [#78](https://github.com/bbatsov/crux/pull/78): Add `crux-recentf-find-directory`. Open recently visited directory. diff --git a/crux.el b/crux.el index f6f8420306..f39cc581fc 100644 --- a/crux.el +++ b/crux.el @@ -167,7 +167,7 @@ When in dired mode, open file under the cursor. With a prefix ARG always prompt for command to use." (interactive "P") (let* ((current-file-name - (if (eq major-mode 'dired-mode) + (if (derived-mode-p 'dired-mode) (dired-get-file-for-visit) buffer-file-name)) (open (pcase system-type @@ -224,7 +224,7 @@ If the process in that buffer died, ask to restart." (apply crux-shell-func (list crux-shell-buffer-name))) (format "*%s*" crux-shell-buffer-name)) (when (and (null (get-buffer-process (current-buffer))) - (not (eq major-mode 'eshell-mode)) ; eshell has no process + (not (derived-mode-p 'eshell-mode)) ; eshell has no process (y-or-n-p "The process has died. Do you want to restart it? ")) (kill-buffer-and-window) (crux-visit-shell-buffer))) @@ -494,7 +494,7 @@ When invoke with C-u, the newly created file will be visited. (defun crux-view-url () "Open a new buffer containing the contents of URL." (interactive) - (let* ((default (if (eq major-mode 'org-mode) + (let* ((default (if (derived-mode-p 'org-mode) (org-element-property :raw-link (org-element-context)) (thing-at-point-url-at-point))) (url (read-from-minibuffer "URL: " default))) @@ -589,7 +589,7 @@ buffer is not visiting a file." Meant to be used as `find-file-hook'. See also `crux-reopen-as-root-mode'." (unless (or (tramp-tramp-file-p buffer-file-name) - (equal major-mode 'dired-mode) + (derived-mode-p 'dired-mode) (not (file-exists-p (file-name-directory buffer-file-name))) (file-writable-p buffer-file-name) (crux-file-owned-by-user-p buffer-file-name))