Git Product home page Git Product logo

scratch's People

Contributors

rnchzn avatar

Watchers

 avatar

scratch's Issues

FR: It would be useful to have a `repeat-exit-function` for a `repeat-map`

navigate-thing-2023-01-21_13.14.32.mp4
(defface thing-face
  '((t :background "light gray"))
  "Face for hi-lock mode." :group 'hi-lock-faces)

(defvar thing)

(put 'thing 'thing t)

(put 'thing 'face 'thing-face)

(defvar-local thing-overlay nil)

(defun thing-highlight
    (obj)
  (let*
      ((bounds
	(bounds-of-thing-at-point obj))
       ov)
    (cond
     (thing-overlay
      (move-overlay thing-overlay
		    (car bounds)
		    (cdr bounds)))
     (obj
      (setq ov
	    (make-overlay
	     (car bounds)
	     (cdr bounds)))
      (overlay-put ov 'category 'thing)
      (setq thing-overlay ov)))))

(defun thing-unhighlight nil
  (interactive)
  (when thing-overlay
    (delete-overlay thing-overlay)))


;;; thing-funs

(defun symbol-thing-forward nil
  (interactive)
  (call-interactively 'forward-symbol)
  (thing-highlight 'symbol))

(defun symbol-thing-backward nil
  (interactive)
  (call-interactively 'backward-symbol)
  (thing-highlight 'symbol))

(defun sexp-thing-forward nil
  (interactive)
  (call-interactively 'forward-sexp)
  (thing-highlight 'sexp))

(defun sexp-thing-backward nil
  (interactive)
  (call-interactively 'backward-sexp)
  (thing-highlight 'sexp))

(defun sexp-thing-up nil
  (interactive)
  (call-interactively 'backward-up-list)
  (thing-highlight 'sexp))

(defun sexp-thing-down nil
  (interactive)
  (call-interactively 'down-list)
  (thing-highlight 'sexp))


;;; definitions

(require 'thingatpt)

(define-key input-decode-map
	    (kbd "s-l")
	    (kbd "<right>"))

(defvar-keymap forward-thing-map "." 'symbol-thing-forward "x" 'sexp-thing-forward)

(global-set-key
 (kbd "<right>")
 forward-thing-map)

(define-key input-decode-map
	    (kbd "s-j")
	    (kbd "<left>"))

(defvar-keymap backward-thing-map "." 'symbol-thing-backward "x" 'sexp-thing-backward)

(global-set-key
 (kbd "<left>")
 backward-thing-map)

(define-key input-decode-map
	    (kbd "s-i")
	    (kbd "<up>"))

(defvar-keymap mark-thing-map)

(global-set-key
 (kbd "<up>")
 mark-thing-map)

(define-key input-decode-map
	    (kbd "s-k")
	    (kbd "<down>"))

(defvar-keymap beginning-thing-map)

(global-set-key
 (kbd "<down>")
 beginning-thing-map)

(defvar-keymap thing-symbol-map :repeat
	       (:enter
		(symbol-thing-forward symbol-thing-backward forward-symbol backward-symbol)
		:exit
		(sexp-thing-up))
	       "]" 'symbol-thing-forward "<right>" 'symbol-thing-forward "[" 'symbol-thing-backward "<left>" 'symbol-thing-backward "<up>" 'sexp-thing-up)

(dolist
    (fn
     '(symbol-thing-forward symbol-thing-backward forward-symbol backward-symbol sexp-thing-up))
  (put fn 'repeat-check-key 'no))

(put 'thing-symbol-map 'repeat-exit-function 'thing-unhighlight)

(defvar-keymap thing-sexp-map :repeat
	       (:enter
		(sexp-thing-forward sexp-thing-backward sexp-thing-up sexp-thing-down forward-sexp backward-sexp backward-up-list down-list)
		:exit nil)
	       "]" 'sexp-thing-forward "<right>" 'sexp-thing-forward "[" 'sexp-thing-backward "<left>" 'sexp-thing-backward "<up>" 'sexp-thing-up "<down>" 'sexp-thing-down)

(dolist
    (fn
     '(sexp-thing-forward sexp-thing-backward sexp-thing-up sexp-thing-down forward-sexp backward-sexp backward-up-list down-list))
  (put fn 'repeat-check-key 'no))

(put 'thing-sexp-map 'repeat-exit-function 'thing-unhighlight)


;;; general

(defun thing-backward
    (which-thing)
  (interactive)
  (forward-thing which-thing -1))

(defun backward-symbol nil
  (interactive)
  (thing-backward 'symbol))

(repeat-mode -1)

(repeat-mode 1)


(provide 'thing)


Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.