Line-wise selections via the left margin

This commit is contained in:
Henrik Lissner 2015-11-08 17:59:11 -05:00
parent 860ca2d96c
commit 0d9411702c
2 changed files with 39 additions and 48 deletions

View file

@ -1,57 +1,43 @@
;;; defuns-editor.el ;;; defuns-editor.el
;; for ../core-editor.el ;; for ../core-editor.el
;; A hacky attempt to replace ace-jump line mode that incrementally shows where (defvar *linum-mdown-line* nil)
;; you will land as you type the line number.
(defun narf--goto-line (line) (defun narf--line-at-click ()
(let ((lines (count-lines (point-min) (point-max)))) (save-excursion
(if (and (<= line (1+ lines)) (let ((click-y (cdr (cdr (mouse-position))))
(> line 0)) (line-move-visual-store line-move-visual))
(narf/nlinum-hl-line line) (setq line-move-visual t)
(narf/nlinum-hl-line)))) (goto-char (window-start))
(next-line (1- click-y))
(setq line-move-visual line-move-visual-store)
;; If you are using tabbar substitute the next line with
;; (line-number-at-pos))))
(1+ (line-number-at-pos)))))
;;;###autoload ;;;###autoload
(defun narf/editor-goto-line () (defun narf/mouse-drag-line ()
(interactive) (interactive)
(let ((keys '()) (goto-line (narf--line-at-click))
(orig-point (point)) (set-mark (point))
(echo-keystrokes 0)) (setq *linum-mdown-line* (line-number-at-pos)))
(evil-save-echo-area
(catch 'abort ;;;###autoload
(while t (defun narf/mouse-select-line ()
(let* ((keystr (concat keys)) (interactive)
(key (read-event (concat ":" keystr)))) (when *linum-mdown-line*
(cond ((eq key 'escape) (let (mu-line)
(message "%s" key) (setq mu-line (narf--line-at-click))
(throw 'abort t)) (goto-line linum-mdown-line*)
((eq key 'return) (if (> mu-line *linum-mdown-line*)
(when keys
(goto-line (string-to-number keystr)))
(throw 'abort t))
((eq key 'backspace)
(let ((key-len (length keys)))
(if (= key-len 0)
(throw 'abort t)
(if (> key-len 1)
(progn (progn
(nbutlast keys) (set-mark (point))
(narf--goto-line (string-to-number (concat keys)))) (goto-line mu-line)
(setq keys '()) (end-of-line))
(narf/nlinum-hl-line))))) (set-mark (line-end-position))
((and (characterp key) (goto-line mu-line)
(s-numeric? (char-to-string key))) (beginning-of-line))
(setq keys (append keys (list key))) (setq *linum-mdown* nil))))
(narf--goto-line (string-to-number (concat keys))))
(t
(if (or (char-equal key ?\C-n)
(char-equal key ?\C-j))
(progn
(setq keys (number-to-string (1+ (string-to-number (concat keys)))))
(narf--goto-line (string-to-number (concat keys))))
(when (or (char-equal key ?\C-p)
(char-equal key ?\C-k))
(setq keys (number-to-string (1- (string-to-number (concat keys)))))
(narf--goto-line (string-to-number (concat keys)))))))))))))
(provide 'defuns-editor) (provide 'defuns-editor)
;;; defuns-editor.el ends here ;;; defuns-editor.el ends here

View file

@ -306,6 +306,11 @@
"<s-right>" 'move-beginning-of-line "<s-right>" 'move-beginning-of-line
"<s-backspace>" 'evil-delete-whole-line)) "<s-backspace>" 'evil-delete-whole-line))
;; Line-wise mouse selection on margin
(global-set-key (kbd "<left-margin> <down-mouse-1>") 'narf/mouse-drag-line)
(global-set-key (kbd "<left-margin> <mouse-1>") 'narf/mouse-select-line)
(global-set-key (kbd "<left-margin> <drag-mouse-1>") 'narf/mouse-select-line)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Keymap fixes ;; ;; Keymap fixes ;;