[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/evil-matchit 64791bc376 105/244: clean code
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/evil-matchit 64791bc376 105/244: clean code |
Date: |
Thu, 6 Jan 2022 02:58:53 -0500 (EST) |
branch: elpa/evil-matchit
commit 64791bc3762a91fafd46c0a598136698321eea16
Author: Chen Bin <chenbin.sh@gmail.com>
Commit: Chen Bin <chenbin.sh@gmail.com>
clean code
---
evil-matchit.el | 144 ++++++++++++++++++++++----------------------------------
1 file changed, 55 insertions(+), 89 deletions(-)
diff --git a/evil-matchit.el b/evil-matchit.el
index d4b9305c96..a4f1e2a152 100644
--- a/evil-matchit.el
+++ b/evil-matchit.el
@@ -1,6 +1,6 @@
;;; evil-matchit.el --- Vim matchit ported to Evil
-;; Copyright (C) 2014,2015 Chen Bin
+;; Copyright (C) 2014-2016 Chen Bin <chenbin.sh@gmail.com>
;; Author: Chen Bin <chenbin.sh@gmail.com>
;; URL: http://github.com/redguardtoo/evil-matchit
@@ -57,14 +57,12 @@ If this flag is nil, then 50 means jump 50 times.")
(defvar evilmi-debug nil)
(defun evilmi--char-is-simple (ch)
- (let (rlt)
- (setq rlt
- (or (memq ch evilmi-forward-chars)
- (memq ch evilmi-backward-chars)
- ;; sorry we could not jump between ends of string in python-mode
- (memq ch evilmi-quote-chars)))
-
- (when (and (memq major-mode '(python-mode))
+ (let* ((rlt (or (memq ch evilmi-forward-chars)
+ (memq ch evilmi-backward-chars)
+ ;; sorry we could not jump between ends of string in
python-mode
+ (memq ch evilmi-quote-chars))))
+
+ (if (and (memq major-mode '(python-mode))
;; in evil-visual-state, (point) could equal to
(line-end-position)
(>= (point) (1- (line-end-position))))
;; handle follow python code,
@@ -78,59 +76,48 @@ If this flag is nil, then 50 means jump 50 times.")
rlt))
(defun evilmi--get-char-at-position (pos)
- (let (ch)
- ;; evil load
- (setq ch (char-after pos))
+ (let* ((ch (char-after pos)))
(if evilmi-debug (message "evilmi--get-char-at-position called. Return:
%s" (string ch)))
ch))
(defun evilmi--get-char-under-cursor ()
"Return: (character position)"
- (let (ch p)
- (setq ch (following-char))
- (setq p (point))
+ (let* ((ch (following-char))
+ (p (point)))
(if evilmi-debug (message "evilmi--get-char-under-cursor called. Return:
(%d %s)" ch p))
(list ch p)))
(defun evilmi--is-jump-forward ()
"Return: (forward-direction font-face-under-cursor character-under-cursor)
If font-face-under-cursor is NOT nil, the quoted string is being processed"
- (let (tmp
- p
- ff
- ch
- rlt)
- (setq tmp (evilmi--get-char-under-cursor))
- (setq ch (car tmp))
- (setq p (cadr tmp))
+ (let* ((tmp (evilmi--get-char-under-cursor))
+ (ch (car tmp))
+ (p (cadr tmp))
+ ff
+ rlt)
(cond
((memq ch evilmi-forward-chars)
(setq rlt t))
((memq ch evilmi-backward-chars)
(setq rlt nil))
((memq ch evilmi-quote-chars)
- (setq ff (get-text-property p 'face))
- (setq rlt (eq ff (get-text-property (+ 1 p) 'face))))
+ (setq rlt (eq (setq ff (get-text-property p 'face))
+ (get-text-property (+ 1 p) 'face))))
(t (setq rlt t)))
- (if evilmi-debug (message "evilmi--is-jump-forward called. Return: (%s %s
%s)"
- rlt ff (string ch)))
-
+ (if evilmi-debug (message "evilmi--is-jump-forward return (%s %s %s)" rlt
ff (string ch)))
(list rlt ff ch)))
(defun evilmi--scan-sexps (is-forward)
- (let (rlt
- start-pos
- (arg (if is-forward 1 -1)))
+ (let* ((start-pos (if is-forward (point) (+ 1 (point))))
+ (arg (if is-forward 1 -1))
+ (rlt (scan-sexps start-pos arg)))
;; normal state and other state
- (setq start-pos (if is-forward (point) (+ 1 (point))))
- (setq rlt (scan-sexps start-pos arg))
(if evilmi-debug (message "evilmi--scan-sexps called. Return: %s" rlt))
rlt))
(defun evilmi--adjust-quote-jumpto (is-forward pos)
- (let (rlt)
- (setq rlt (if is-forward pos (+ 1 pos)))
+ (let* ((rlt (if is-forward pos (+ 1 pos))))
(if evilmi-debug (message "evilmi--adjust-quote-jumpto called. Return: %s"
rlt))
rlt))
@@ -139,13 +126,12 @@ If font-face-under-cursor is NOT nil, the quoted string
is being processed"
(not (eq ff (get-text-property pos 'face)))))
(defun evilmi--find-the-other-quote-char (ff is-forward ch)
-"The end character under cursor has different font-face from ff"
- (let (rlt
- pos
- (got nil)
- (delta (if is-forward 1 -1))
- (end (if is-forward (point-max) (point-min))))
- (setq pos (+ delta (point)))
+ "The end character under cursor has different font-face from ff"
+ (let* (rlt
+ (got nil)
+ (delta (if is-forward 1 -1))
+ (pos (+ delta (point)))
+ (end (if is-forward (point-max) (point-min))))
(while (not got)
(if (or (= pos end)
(evilmi--above-the-other-quote-char ch pos ff delta))
@@ -166,12 +152,10 @@ If font-face-under-cursor is NOT nil, the quoted string
is being processed"
;; @see
http://emacs.stackexchange.com/questions/13222/a-elisp-function-to-jump-between-matched-pair
(defun evilmi--find-position-to-jump (ff is-forward ch)
"Non-nil ff means jumping between quotes"
- (let (rlt)
- (if ff (setq rlt (evilmi--find-the-other-quote-char ff is-forward ch))
- (setq rlt (evilmi--scan-sexps is-forward)))
- (setq rlt (evilmi--adjust-jumpto is-forward rlt))
- (if evilmi-debug (message "evilmi--find-position-to-jump called. Return:
%s" rlt))
- rlt))
+ (let* ((rlt (if ff (evilmi--find-the-other-quote-char ff is-forward ch)
+ (evilmi--scan-sexps is-forward))))
+ (if evilmi-debug (message "evilmi--find-position-to-jump return %s"
(evilmi--adjust-jumpto is-forward rlt)))
+ (evilmi--adjust-jumpto is-forward rlt)))
(defun evilmi--tweak-selected-region-finally (ff jump-forward)
;; visual-state hack!
@@ -181,33 +165,26 @@ If font-face-under-cursor is NOT nil, the quoted string
is being processed"
(evil-backward-char)))
(defun evilmi--simple-jump ()
- "Alternative for evil-jump-item"
+ "Alternative for evil-jump-item."
;; parse-sexp-ignore-comments is used
(interactive)
- (let ((old-flag parse-sexp-ignore-comments)
- tmp
- ch
- jumpto
- ff
- jump-forward)
- (setq tmp (evilmi--is-jump-forward))
- (setq jump-forward (car tmp))
- ;; if ff is not nil, it's jump between quotes
- ;; so we should not use (scan-sexps)
- (setq ff (nth 1 tmp))
- (setq ch (nth 2 tmp))
+ (let* ((old-flag parse-sexp-ignore-comments)
+ (tmp (evilmi--is-jump-forward))
+ (jump-forward (car tmp))
+ ;; if ff is not nil, it's jump between quotes
+ ;; so we should not use (scan-sexps)
+ (ff (nth 1 tmp))
+ (ch (nth 2 tmp)))
(unless evilmi-ignore-comments
(setq parse-sexp-ignore-comments nil))
;; need pass the char
- (setq jumpto (evilmi--find-position-to-jump ff jump-forward ch))
- (goto-char jumpto)
+ (goto-char (evilmi--find-position-to-jump ff jump-forward ch))
(evilmi--tweak-selected-region-finally ff jump-forward)
(unless evilmi-ignore-comments
- (setq parse-sexp-ignore-comments old-flag))
- ))
+ (setq parse-sexp-ignore-comments old-flag))))
(defun evilmi--operate-on-item (NUM &optional FUNC)
(let ((plugin (plist-get evilmi-plugins major-mode))
@@ -228,8 +205,7 @@ If font-face-under-cursor is NOT nil, the quoted string is
being processed"
;; jump now, execute evilmi-xxxx-jump
(setq where-to-jump-in-theory (funcall (nth 1 elem) rlt NUM))
;; jump only once if the jump is successful
- (setq jumped t)
- ))
+ (setq jumped t)))
plugin))
;; give `evilmi--simple-jump' a chance
@@ -246,7 +222,6 @@ If font-face-under-cursor is NOT nil, the quoted string is
being processed"
(defun evilmi-init-plugins ()
(interactive)
-
;; simple matching for languages containing "{(["
(autoload 'evilmi-simple-get-tag "evil-matchit-simple" nil)
(autoload 'evilmi-simple-jump "evil-matchit-simple" nil)
@@ -345,8 +320,7 @@ If font-face-under-cursor is NOT nil, the quoted string is
being processed"
(mapc (lambda (mode)
(plist-put evilmi-plugins mode '((evilmi-simple-get-tag
evilmi-simple-jump)
(evilmi-ruby-get-tag
evilmi-ruby-jump))))
- '(ruby-mode enh-ruby-mode))
- )
+ '(ruby-mode enh-ruby-mode)))
(defun evilmi--region-to-select-or-delete (NUM &optional is-inner)
(let (where-to-jump-in-theory b e)
@@ -364,32 +338,28 @@ If font-face-under-cursor is NOT nil, the quoted string
is being processed"
(setq b (line-beginning-position)))
(t
(if (string-match "[ \t]*" (buffer-substring-no-properties
(line-beginning-position) b))
- (setq b (line-beginning-position))
- ;; 1+ because the line feed
- )))
+ (setq b (line-beginning-position)))))
;; for inner text object, backward a line at the end
;; but in python-mode, last line is also code line
(when (and is-inner (not (eq major-mode 'python-mode)))
(goto-char e)
(forward-line -1)
- (setq e (line-end-position)))
- )
+ (setq e (line-end-position))))
+
(if evilmi-debug (message "evilmi--region-to-select-or-delete called.
Return: %s" (list b e)))
(list b e)))
(evil-define-text-object evilmi-inner-text-object (&optional NUM begin end
type)
"Inner text object describing the region selected when you press % from
evil-matchit"
:type line
- (let (selected-region)
- (setq selected-region (evilmi--region-to-select-or-delete NUM t))
+ (let* ((selected-region (evilmi--region-to-select-or-delete NUM t)))
(evil-range (car selected-region) (cadr selected-region) 'line)))
(evil-define-text-object evilmi-outer-text-object (&optional NUM begin end
type)
"Outer text object describing the region selected when you press % from
evil-matchit"
:type line
- (let (selected-region)
- (setq selected-region (evilmi--region-to-select-or-delete NUM))
+ (let ((selected-region (evilmi--region-to-select-or-delete NUM)))
(evil-range (car selected-region) (cadr selected-region) 'line)))
(define-key evil-inner-text-objects-map "%" 'evilmi-inner-text-object)
@@ -399,22 +369,18 @@ If font-face-under-cursor is NOT nil, the quoted string
is being processed"
(defun evilmi-select-items (&optional NUM)
"Select items/tags and the region between them"
(interactive "p")
- (let (selected-region)
- (setq selected-region (evilmi--region-to-select-or-delete NUM))
+ (let* ((selected-region (evilmi--region-to-select-or-delete NUM)))
(when selected-region
(evilmi--push-mark selected-region)
- (goto-char (cadr selected-region)))
- ))
+ (goto-char (cadr selected-region)))))
;;;###autoload
(defun evilmi-delete-items (&optional NUM)
"Delete items/tags and the region between them"
(interactive "p")
- (let (selected-region)
- (setq selected-region (evilmi--region-to-select-or-delete NUM))
+ (let* ((selected-region (evilmi--region-to-select-or-delete NUM)))
;; 1+ because the line feed
- (kill-region (car selected-region) (1+ (cadr selected-region)))
- ))
+ (kill-region (car selected-region) (1+ (cadr selected-region)))))
;;;###autoload
(defun evilmi-jump-to-percentage (NUM)
@@ -442,8 +408,8 @@ If font-face-under-cursor is NOT nil, the quoted string is
being processed"
(cond
((and evilmi-may-jump-by-percentage NUM)
(evilmi-jump-to-percentage NUM))
- (t (evilmi--operate-on-item NUM))
- ))
+ (t
+ (evilmi--operate-on-item NUM))))
;;;###autoload
(defun evilmi-version() (interactive) (message "2.1.3"))
- [nongnu] elpa/evil-matchit 8b4db43dc2 075/244: Merge pull request #44 from thegreatape/master, (continued)
- [nongnu] elpa/evil-matchit 8b4db43dc2 075/244: Merge pull request #44 from thegreatape/master, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit af40d309c6 078/244: documentation, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 89fd968ac2 080/244: spacemacs use enh-ruby-mode, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit ff29cd2264 084/244: workaround issue in python-mode v2.0.2, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 63846fc4c0 089/244: Add melpa badge, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 62d948743e 092/244: updated README, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 98c045d352 094/244: Merge pull request #61 from robbyoconnor/patch-2, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 94e359e30c 095/244: Fix embedded major-mode detection in org-mode, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit c675e740a7 101/244: can simple jump in latex-mode, #70, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 34c51f68fd 102/244: jump in diff-mode, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 64791bc376 105/244: clean code,
ELPA Syncer <=
- [nongnu] elpa/evil-matchit 51d46747e3 108/244: support Facebook React JSX, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 8a56092b38 110/244: can handle `render()` in jsx, code cleaned, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit bed39041b1 123/244: support markdown, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 7d65b4167b 156/244: clean plugins setup code, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit b63f840ee7 124/244: When on whitespace following a keyword don't jump backwards, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 20270ab6b0 135/244: support one liner, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 51d8b268e5 138/244: Merge pull request #86 from yqrashawn/support-tsx, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit dbaae2b753 127/244: Merge pull request #81 from neojski/ocaml, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit dea3fca13b 168/244: clean code dependency, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 64b572d2e4 166/244: Merge pull request #107 from porras/patch-2, ELPA Syncer, 2022/01/06