-
Notifications
You must be signed in to change notification settings - Fork 11
/
hui-dired-sidebar.el
84 lines (70 loc) · 3.08 KB
/
hui-dired-sidebar.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
;;; hui-dired-sidebar.el --- Hyperbole Smart Key support for dired sidebar -*- lexical-binding: t; -*-
;;
;; Author: Mats Lidell
;;
;; Orig-Date: 25-Jul-20
;; Last-Mod: 19-Jan-24 at 12:13:30 by Mats Lidell
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
;; Copyright (C) 2020-2021 Free Software Foundation, Inc. See the
;; "HY-COPY" file for license information.
;;
;; This file is part of GNU Hyperbole.
;;; Commentary:
;;; Code:
;;; ************************************************************************
;;; Other required Elisp libraries
;;; ************************************************************************
(eval-and-compile (require 'dired-sidebar nil t))
;;; ************************************************************************
;;; Public declarations
;;; ************************************************************************
(defvar dired-sidebar-cycle-subtree-on-click)
(defvar assist-flag) ; "hmouse-drv.el"
(defvar action-key-eol-function) ; "hmouse-drv.el"
(defvar assist-key-eol-function) ; "hmouse-drv.el"
(declare-function dired-sidebar-toggle-sidebar "ext:dired-sidebar")
(declare-function dired-get-file-for-visit "dired")
(declare-function hact "hact")
(declare-function first-line-p "hui-mouse")
(declare-function last-line-p "hui-mouse")
;;; ************************************************************************
;;; smart-dired-sidebar functions
;;; ************************************************************************
;;;###autoload
(defun smart-dired-sidebar ()
"Use a single key or mouse key to manipulate directory entries.
Invoked via a key press when in dired-sidebar-mode. It assumes
that its caller has already checked that the key was pressed in
an appropriate buffer and has moved the cursor there.
If key is pressed:
(1) within an entry line, the item is displayed for editing,
normally in another window, or if it is a directory and
`dired-sidebar-cycle-subtree-on-click' is t it will expand
and collapse the entry
(2) at the end of an entry line: invoke `action-key-eol-function',
typically to scroll up proportionally, if an Action Key press; invoke
`assist-key-eol-function', typically to scroll down proportionally,
if an Asisst Key press;
(3) on the first line of the buffer (other than the end of line),
Dired is run on the current directory of this dired-sidebar;
(4) at the end of the first or last line of the buffer,
this dired-sidebar invocation is hidden."
(interactive)
(cond ((first-line-p)
(if (eolp)
(dired-sidebar-toggle-sidebar)
(hact 'link-to-directory default-directory)))
((and (last-line-p) (eolp))
(dired-sidebar-toggle-sidebar))
((eolp)
(funcall (if assist-flag assist-key-eol-function action-key-eol-function)))
(t (let ((file (dired-get-file-for-visit)))
(if (and dired-sidebar-cycle-subtree-on-click
(file-directory-p file)
(not (string-suffix-p "." file)))
(hact 'dired-sidebar-subtree-toggle)
(hact 'dired-sidebar-find-file file))))))
(provide 'hui-dired-sidebar)
;;; hui-dired-sidebar.el ends here