-
Notifications
You must be signed in to change notification settings - Fork 11
/
hmouse-sh.el
571 lines (528 loc) · 21.3 KB
/
hmouse-sh.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
;;; hmouse-sh.el --- System-dependent Smart Mouse Key bindings. -*- lexical-binding: t; -*-
;;
;; Author: Bob Weiner
;;
;; Orig-Date: 3-Sep-91 at 21:40:58
;; Last-Mod: 20-Jan-24 at 20:52:12 by Mats Lidell
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
;; Copyright (C) 1991-2022 Free Software Foundation, Inc.
;; See the "HY-COPY" file for license information.
;;
;; This file is part of GNU Hyperbole.
;;; Commentary:
;;
;; See description in "hmouse-key.el".
;;; Code:
;;; ************************************************************************
;;; Other required Elisp libraries
;;; ************************************************************************
(require 'hvar)
(require 'kmacro)
;;; ************************************************************************
;;; Public declarations
;;; ************************************************************************
(defvar br-env-spec)
(defvar br-lang-prefix)
(defvar company-active-map)
(defvar java-class-def-name-grpn)
(defvar java-class-def-regexp)
(defvar jedi-mode)
(defvar hmouse-bindings-flag) ; "hmouse-key.el"
(defvar hmouse-previous-bindings) ; "hmouse-key.el"
(defvar hmouse-set-point-command) ; "hui-mouse.el"
(defvar hmouse-bindings) ; "hmouse-key.el"
(defvar hmouse-bindings-flag) ; "hmouse-key.el"
(defvar Info-mode-map)
(declare-function action-key-depress-emacs "hmouse-drv")
(declare-function action-mouse-key-emacs "hmouse-drv")
(declare-function assist-key-depress-emacs "hmouse-drv")
(declare-function assist-mouse-key-emacs "hmouse-drv")
(declare-function action-key-depress "hmouse-drv")
(declare-function hkey-set-key "hyperbole")
;;; ************************************************************************
;;; Public functions
;;; ************************************************************************
;; Other mouse event location prefixes to possibly handle:
;; vertical-scroll-bar
;; horizontal-scroll-bar
;; right-divider
;; bottom-divider
;; tab-bar sample Smart Mouse setup
;; (define-key tab-prefix-map [down-mouse-2] #'action-key-depress-emacs)
;; (define-key tab-prefix-map [mouse-2] #'action-mouse-key-emacs)
;; tab-line sample Smart Mouse setup
;; (define-key tab-line-tab-map [tab-line down-mouse-2] #'action-key-depress-emacs)
;; (define-key tab-line-tab-map [tab-line mouse-2] #'action-mouse-key-emacs)
(defun hmouse-bind-key-emacs (mouse-key-number depress-cmd release-cmd)
"Ensure MOUSE-KEY-NUMBER (1-5) is bound to DEPRESS-CMD and RELEASE-CMD.
This includes depresses and drags. Mouse key 1 is [\\`mouse-1'], etc.
Use nil as cmd value to unbind a key."
(hmouse-set-key-list
depress-cmd
(nth (1- mouse-key-number)
'(
([down-mouse-1]
[double-down-mouse-1] [triple-down-mouse-1]
[header-line down-mouse-1]
[left-fringe down-mouse-1]
[right-fringe down-mouse-1]
[vertical-line down-mouse-1]
[mode-line down-mouse-1])
([down-mouse-2]
[double-down-mouse-2] [triple-down-mouse-2]
[header-line down-mouse-2]
[left-fringe down-mouse-2]
[right-fringe down-mouse-2]
[vertical-line down-mouse-2]
[mode-line down-mouse-2])
([down-mouse-3]
[double-down-mouse-3] [triple-down-mouse-3]
[header-line down-mouse-3]
[left-fringe down-mouse-3]
[right-fringe down-mouse-3]
[vertical-line down-mouse-3]
[mode-line down-mouse-3])
([down-mouse-4]
[double-down-mouse-4] [triple-down-mouse-4]
[header-line down-mouse-4]
[left-fringe down-mouse-4]
[right-fringe down-mouse-4]
[vertical-line down-mouse-4]
[mode-line down-mouse-4])
([down-mouse-5]
[double-down-mouse-5] [triple-down-mouse-5]
[header-line down-mouse-5]
[left-fringe down-mouse-5]
[right-fringe down-mouse-5]
[vertical-line down-mouse-5]
[mode-line down-mouse-5]))))
(hmouse-set-key-list
release-cmd
(nth (1- mouse-key-number)
'(
([drag-mouse-1] [mouse-1]
[double-mouse-1] [triple-mouse-1]
[header-line drag-mouse-1]
[header-line mouse-1]
[left-fringe drag-mouse-1]
[left-fringe mouse-1]
[right-fringe drag-mouse-1]
[right-fringe mouse-1]
[vertical-line drag-mouse-1]
[vertical-line mouse-1]
[mode-line drag-mouse-1]
[mode-line mouse-1])
([drag-mouse-2] [mouse-2]
[double-mouse-2] [triple-mouse-2]
[header-line drag-mouse-2]
[header-line mouse-2]
[left-fringe drag-mouse-2]
[left-fringe mouse-2]
[right-fringe drag-mouse-2]
[right-fringe mouse-2]
[vertical-line drag-mouse-2]
[vertical-line mouse-2]
[mode-line drag-mouse-2]
[mode-line mouse-2])
([drag-mouse-3] [mouse-3]
[double-mouse-3] [triple-mouse-3]
[header-line drag-mouse-3]
[header-line mouse-3]
[left-fringe drag-mouse-3]
[left-fringe mouse-3]
[right-fringe drag-mouse-3]
[right-fringe mouse-3]
[vertical-line drag-mouse-3]
[vertical-line mouse-3]
[mode-line drag-mouse-3]
[mode-line mouse-3])
([drag-mouse-4] [mouse-4]
[double-mouse-4] [triple-mouse-4]
[header-line drag-mouse-4]
[header-line mouse-4]
[left-fringe drag-mouse-4]
[left-fringe mouse-4]
[right-fringe drag-mouse-4]
[right-fringe mouse-4]
[vertical-line drag-mouse-4]
[vertical-line mouse-4]
[mode-line drag-mouse-4]
[mode-line mouse-4])
([drag-mouse-5] [mouse-5]
[double-mouse-5] [triple-mouse-5]
[header-line drag-mouse-5]
[header-line mouse-5]
[left-fringe drag-mouse-5]
[left-fringe mouse-5]
[right-fringe drag-mouse-5]
[right-fringe mouse-5]
[vertical-line drag-mouse-5]
[vertical-line mouse-5]
[mode-line drag-mouse-5]
[mode-line mouse-5])))))
(defun hmouse-bind-shifted-key-emacs (shifted-mouse-key-number depress-cmd release-cmd)
"Ensure SHIFTED-MOUSE-KEY-NUMBER (1-5) is bound to DEPRESS-CMD and RELEASE-CMD.
This includes depresses and drags. Shifted Mouse Key 1 is
[S-mouse-1], etc. Use nil as cmd value to unbind the key."
(hmouse-set-key-list
depress-cmd
(nth (1- shifted-mouse-key-number)
'(
([S-down-mouse-1] [header-line S-down-mouse-1]
[left-fringe S-down-mouse-1]
[right-fringe S-down-mouse-1]
[vertical-line S-down-mouse-1]
[mode-line S-down-mouse-1])
([S-down-mouse-2] [header-line S-down-mouse-2]
[left-fringe S-down-mouse-2]
[right-fringe S-down-mouse-2]
[vertical-line S-down-mouse-2]
[mode-line S-down-mouse-2])
([S-down-mouse-3] [header-line S-down-mouse-3]
[left-fringe S-down-mouse-3]
[right-fringe S-down-mouse-3]
[vertical-line S-down-mouse-3]
[mode-line S-down-mouse-3])
([S-down-mouse-4] [header-line S-down-mouse-4]
[left-fringe S-down-mouse-4]
[right-fringe S-down-mouse-4]
[vertical-line S-down-mouse-4]
[mode-line S-down-mouse-4])
([S-down-mouse-5] [header-line S-down-mouse-5]
[left-fringe S-down-mouse-5]
[right-fringe S-down-mouse-5]
[vertical-line S-down-mouse-5]
[mode-line S-down-mouse-5]))))
(hmouse-set-key-list
release-cmd
(nth (1- shifted-mouse-key-number)
'(
([S-drag-mouse-1] [S-mouse-1]
[S-double-mouse-1] [S-triple-mouse-1]
[header-line S-drag-mouse-1]
[header-line S-mouse-1]
[left-fringe S-drag-mouse-1]
[left-fringe S-mouse-1]
[right-fringe S-drag-mouse-1]
[right-fringe S-mouse-1]
[vertical-line S-drag-mouse-1]
[vertical-line S-mouse-1]
[mode-line S-drag-mouse-1]
[mode-line S-mouse-1])
([S-drag-mouse-2] [S-mouse-2]
[S-double-mouse-2] [S-triple-mouse-2]
[header-line S-drag-mouse-2]
[header-line S-mouse-2]
[left-fringe S-drag-mouse-2]
[left-fringe S-mouse-2]
[right-fringe S-drag-mouse-2]
[right-fringe S-mouse-2]
[vertical-line S-drag-mouse-2]
[vertical-line S-mouse-2]
[mode-line S-drag-mouse-2]
[mode-line S-mouse-2])
([S-drag-mouse-3] [S-mouse-3]
[S-double-mouse-3] [S-triple-mouse-3]
[header-line S-drag-mouse-3]
[header-line S-mouse-3]
[left-fringe S-drag-mouse-3]
[left-fringe S-mouse-3]
[right-fringe S-drag-mouse-3]
[right-fringe S-mouse-3]
[vertical-line S-drag-mouse-3]
[vertical-line S-mouse-3]
[mode-line S-drag-mouse-3]
[mode-line S-mouse-3])
([S-drag-mouse-4] [S-mouse-4]
[S-double-mouse-4] [S-triple-mouse-4]
[header-line S-drag-mouse-4]
[header-line S-mouse-4]
[left-fringe S-drag-mouse-4]
[left-fringe S-mouse-4]
[right-fringe S-drag-mouse-4]
[right-fringe S-mouse-4]
[vertical-line S-drag-mouse-4]
[vertical-line S-mouse-4]
[mode-line S-drag-mouse-4]
[mode-line S-mouse-4])
([S-drag-mouse-5] [S-mouse-5]
[S-double-mouse-5] [S-triple-mouse-5]
[header-line S-drag-mouse-5]
[header-line S-mouse-5]
[left-fringe S-drag-mouse-5]
[left-fringe S-mouse-5]
[right-fringe S-drag-mouse-5]
[right-fringe S-mouse-5]
[vertical-line S-drag-mouse-5]
[vertical-line S-mouse-5]
[mode-line S-drag-mouse-5]
[mode-line S-mouse-5])))))
(defun hmouse-get-bindings (middle-flag)
"Return the list of active bindings of mouse keys used by Hyperbole.
If MIDDLE-FLAG is non-nil, include the middle mouse key
binding as well. These may be the bindings prior to initializing
Hyperbole or the Hyperbole bindings."
;; Do nothing when running in batch mode.
(unless noninteractive
(nconc
(when middle-flag (hmouse-get-unshifted-bindings))
;; Get mouse bindings under Emacs, even if not under a window
;; system, since there can be frames on ttys and windowed
;; displays at the same time.
(mapcar (lambda (key) (cons key (key-binding key)))
(if (eq window-system 'dps)
;; NEXTSTEP offers only 2 shift-mouse buttons which we use
;; as the Smart Keys.
'([S-down-mouse-1] [S-drag-mouse-1] [S-mouse-1]
[S-down-mouse-2] [S-drag-mouse-2] [S-mouse-2]
[S-double-mouse-1] [S-triple-mouse-1]
[S-double-mouse-2] [S-triple-mouse-2]
[header-line S-down-mouse-1] [header-line S-drag-mouse-1]
[header-line S-mouse-1]
[header-line S-down-mouse-2] [header-line S-drag-mouse-2]
[header-line S-mouse-2]
[left-fringe S-down-mouse-1] [left-fringe S-drag-mouse-1]
[left-fringe S-mouse-1]
[left-fringe S-down-mouse-2] [left-fringe S-drag-mouse-2]
[left-fringe S-mouse-2]
[right-fringe S-down-mouse-1] [right-fringe S-drag-mouse-1]
[right-fringe S-mouse-1]
[right-fringe S-down-mouse-2] [right-fringe S-drag-mouse-2]
[right-fringe S-mouse-2]
[vertical-line S-down-mouse-1] [vertical-line S-drag-mouse-1]
[vertical-line S-mouse-1]
[vertical-line S-down-mouse-2] [vertical-line S-drag-mouse-2]
[vertical-line S-mouse-2]
[mode-line S-down-mouse-1] [mode-line S-drag-mouse-1]
[mode-line S-mouse-1]
[mode-line S-down-mouse-2] [mode-line S-drag-mouse-2]
[mode-line S-mouse-2])
;; X, macOS or MS Windows
'([S-down-mouse-2] [S-drag-mouse-2] [S-mouse-2]
[S-down-mouse-3] [S-drag-mouse-3] [S-mouse-3]
[S-double-mouse-2] [S-triple-mouse-2]
[S-double-mouse-3] [S-triple-mouse-3]
[header-line S-down-mouse-2] [header-line S-drag-mouse-2]
[header-line S-mouse-2]
[header-line S-down-mouse-3] [header-line S-drag-mouse-3]
[header-line S-mouse-3]
[left-fringe S-down-mouse-2] [left-fringe S-drag-mouse-2]
[left-fringe S-mouse-2]
[left-fringe S-down-mouse-3] [left-fringe S-drag-mouse-3]
[left-fringe S-mouse-3]
[right-fringe S-down-mouse-2] [right-fringe S-drag-mouse-2]
[right-fringe S-mouse-2]
[right-fringe S-down-mouse-3] [right-fringe S-drag-mouse-3]
[right-fringe S-mouse-3]
[vertical-line S-down-mouse-2] [vertical-line S-drag-mouse-2]
[vertical-line S-mouse-2]
[vertical-line S-down-mouse-3] [vertical-line S-drag-mouse-3]
[vertical-line S-mouse-3]
[mode-line S-down-mouse-2] [mode-line S-drag-mouse-2]
[mode-line S-mouse-2]
[mode-line S-down-mouse-3] [mode-line S-drag-mouse-3]
[mode-line S-mouse-3])))
(nconc
(mapcar (lambda (key)
(cons key (key-binding key)))
'([(shift button2)] [(shift button2up)]
[(shift button3)] [(shift button3up)]))
(when (boundp 'mode-line-map)
(mapcar (lambda (key)
(cons key (lookup-key mode-line-map key)))
'([(shift button3)] [(shift button3up)])))))))
(defun hmouse-get-unshifted-bindings ()
"Return the list of middle mouse key bindings prior to their use as Smart Keys."
;; Do nothing when running in batch mode.
(mapc (lambda (key) (cons key (key-binding key)))
(unless (eq window-system 'dps)
;; X, macOS or MS Windows
'([down-mouse-2] [drag-mouse-2] [mouse-2]
[down-mouse-3] [drag-mouse-3] [mouse-3]
[double-mouse-2] [triple-mouse-2]
[double-mouse-3] [triple-mouse-3]
[header-line down-mouse-2] [header-line drag-mouse-2]
[header-line mouse-2]
[left-fringe down-mouse-2] [left-fringe drag-mouse-2]
[left-fringe mouse-2]
[right-fringe down-mouse-2] [right-fringe drag-mouse-2]
[right-fringe mouse-2]
[vertical-line down-mouse-2] [vertical-line drag-mouse-2]
[vertical-line mouse-2]
[left-fringe down-mouse-3] [left-fringe drag-mouse-3]
[left-fringe mouse-3]
[right-fringe down-mouse-3] [right-fringe drag-mouse-3]
[right-fringe mouse-3]
[vertical-line down-mouse-3] [vertical-line drag-mouse-3]
[vertical-line mouse-3]
[mode-line down-mouse-2] [mode-line drag-mouse-2]
[mode-line mouse-2]
[mode-line down-mouse-3] [mode-line drag-mouse-3]
[mode-line mouse-3])))
(nconc
(mapcar (lambda (key)
(cons key (key-binding key)))
'([button2] [button2up]
[button3] [button3up]))
(when (boundp 'mode-line-map)
(mapcar (function
(lambda (key)
(cons key (lookup-key mode-line-map key))))
'([button3] [button3up])))))
;; Based on a function from Emacs mouse.el.
(defun hmouse-posn-set-point (position)
"Move point to POSITION, an event posn.
Select the corresponding window as well."
(if (framep (posn-window position))
(progn (if (not (windowp (frame-selected-window (posn-window position))))
(error "Position not in text area of window"))
(select-window (frame-selected-window (posn-window position))))
(unless (windowp (posn-window position))
(error "Position not in text area of window"))
(select-window (posn-window position)))
(let ((pos-point (posn-point position)))
;; Need all these checks for vertico-mode
(when (and (numberp pos-point)
(>= pos-point (point-min))
(<= pos-point (point-max)))
(goto-char pos-point))))
;; Based on mouse-drag-region from Emacs mouse.el.
(defun hmouse-drag-region (start-event)
"Set the region to the text that the mouse is dragged over.
If not the start of a region drag-and-drop, and hyperbole-mode is
enabled, then depress the Action Key.
Highlight the drag area as you move the mouse.
This must be bound to a button-down mouse event.
In Transient Mark mode, the highlighting remains as long as the mark
remains active. Otherwise, it remains until the next input event.
When the region already exists and variable `mouse-drag-and-drop-region'
is non-nil, this moves the entire region of text to where mouse
is dragged over to."
(interactive "e")
(if (and mouse-drag-and-drop-region
(not (member 'triple (event-modifiers start-event)))
(equal (mouse-posn-property (event-start start-event) 'face) 'region))
(mouse-drag-and-drop-region start-event)
;; Give temporary modes such as isearch a chance to turn off.
(run-hooks 'mouse-leave-buffer-hook)
(when hyperbole-mode
(action-key-depress start-event))
(mouse-drag-track start-event)))
;; Based on a function from Emacs mouse.el.
(defun hmouse-move-point-emacs (event &optional promote-to-region)
"Move point to the position clicked on with the mouse.
This should be bound to a mouse click event type.
If PROMOTE-TO-REGION is non-nil and EVENT is a multiple-click,
select the corresponding element around point, with the resulting position of
point determined by `mouse-select-region-move-to-beginning'."
(interactive "e\np")
(let ((start-w-or-f (posn-window (event-start event)))
(end-w-or-f (posn-window (event-end event))))
(when (framep start-w-or-f)
(with-selected-frame start-w-or-f (setq start-w-or-f (selected-window))))
(when (framep end-w-or-f)
(with-selected-frame end-w-or-f (setq end-w-or-f (selected-window))))
(if (and (window-valid-p start-w-or-f)
(window-minibuffer-p start-w-or-f)
(not (minibuffer-window-active-p start-w-or-f)))
;; Select the ending frame only, not the window pressed within.
(select-frame (window-frame end-w-or-f))
;; Give temporary modes such as isearch a chance to turn off.
(run-hooks 'mouse-leave-buffer-hook)
(if (and promote-to-region (> (event-click-count event) 1))
(progn (mouse-set-region event)
(when (and (boundp 'mouse-select-region-move-to-beginning)
mouse-select-region-move-to-beginning)
(when (> (posn-point (event-start event)) (region-beginning))
(exchange-point-and-mark))))
;; Use event-end in case called from mouse-drag-region.
;; If EVENT is a click, event-end and event-start give same value.
(if (and (window-valid-p end-w-or-f)
(window-minibuffer-p end-w-or-f)
(not (minibuffer-window-active-p end-w-or-f)))
;; Select the ending frame only, not the window pressed within.
(select-frame (window-frame end-w-or-f))
(condition-case ()
(hmouse-posn-set-point (event-end event))
(error (when (window-valid-p end-w-or-f)
(select-frame (window-frame end-w-or-f))))))))))
(defun hmouse-set-key-list (binding key-list)
"Define a Hyperbole global minor mode key from KEY-LIST bound to BINDING."
(mapc (lambda (key) (hkey-set-key key binding)) key-list)
nil)
(defun hmouse-shifted-setup (middle-flag)
"Call `hmouse-install' instead of this and see its documentation.
When non-nil MIDDLE-FLAG bind the middle and right mouse keys as
Action and Assist Keys, respectively."
(interactive)
;; Do nothing when running in batch mode.
(unless noninteractive
(or hmouse-bindings-flag hmouse-previous-bindings
(setq hmouse-previous-bindings (hmouse-get-bindings middle-flag)))
(when middle-flag (hmouse-unshifted-setup middle-flag))
;; Ensure Gillespie's Info mouse support is off since
;; Hyperbole handles that.
(when (boundp 'Info-mouse-support) (setq Info-mouse-support nil))
;;
;; This event setting from the "kmacro.el" library can
;; trigger an autoload that binds [S-mouse-3] to 'kmacro-end-call-mouse,
;; interfering with the same key used for the Assist Key, so disable
;; this.
(setq kmacro-call-mouse-event nil)
;;
(setq hmouse-set-point-command #'hmouse-move-point-emacs)
(if (eq window-system 'dps)
;; NEXTSTEP offers only 2 shift-mouse buttons which we use as the Smart Keys.
(progn
(hmouse-bind-shifted-key-emacs 1 #'action-key-depress-emacs #'action-mouse-key-emacs)
(hmouse-bind-shifted-key-emacs 2 #'assist-key-depress-emacs #'assist-mouse-key-emacs))
;; X, macOS or MS Windows
(hmouse-bind-shifted-key-emacs 2 #'action-key-depress-emacs #'action-mouse-key-emacs)
(hmouse-bind-shifted-key-emacs 3 #'assist-key-depress-emacs #'assist-mouse-key-emacs)
(with-eval-after-load "company"
(define-key company-active-map [S-down-mouse-2] 'ignore)
(define-key company-active-map [S-mouse-2] 'smart-company-to-definition)
(define-key company-active-map [S-down-mouse-3] 'ignore)
(define-key company-active-map [S-mouse-3] 'smart-company-help)))
(setq hmouse-bindings (hmouse-get-bindings middle-flag)
hmouse-bindings-flag t)))
(defun hmouse-unshifted-setup (&optional middle-key-only-flag)
"Bind the middle and right mouse keys as Action and Assist Keys, respectively.
With optional MIDDLE-KEY-ONLY-FLAG non-nil, bind only the middle mouse key."
(interactive)
;; Globally Emacs uses key-translation-map to link mouse-1 to
;; do whatever mouse-2 does when 'mouse-1-click-follows-link' is
;; non-nil (the default) and point is on an Emacs button.
;; Since Hyperbole rebinds mouse-2 here, this does not work by
;; default. We fix that here by overriding the setting of
;; down-mouse-1 to include the down Action Key command plus the
;; original mouse-1 command. Then when mouse-1 is released on an
;; Emacs button, the Action Key command is run which handles
;; activating the button/following a link.
(global-set-key [down-mouse-1] 'hmouse-drag-region)
;;
;; Unbind Emacs push-button mouse keys since Hyperbole handles them.
(define-key button-map [mouse-2] nil)
(define-key button-map [mode-line mouse-2] nil)
(define-key button-map [header-line mouse-2] nil)
;; Remove push-button help echo string for mouse-2 key.
(put 'default-button 'help-echo nil)
;;
;; Remove mouse-2 binding In Info-mode since Hyperbole handles it.
(var:add-and-run-hook 'Info-mode-hook (lambda () (define-key Info-mode-map [mouse-2] nil)))
;;
(unless (eq window-system 'dps)
;; X, macOS or MS Windows
(hmouse-bind-key-emacs 2 #'action-key-depress-emacs #'action-mouse-key-emacs)
(unless middle-key-only-flag
(hmouse-bind-key-emacs 3 #'assist-key-depress-emacs #'assist-mouse-key-emacs))
`(with-eval-after-load "company"
(define-key company-active-map [down-mouse-2] 'ignore)
(define-key company-active-map [mouse-2] 'smart-company-to-definition)
(unless ,middle-key-only-flag
(define-key company-active-map [down-mouse-3] 'ignore)
(define-key company-active-map [mouse-3] 'smart-company-help)))))
(provide 'hmouse-sh)
;;; hmouse-sh.el ends here