[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/popup 871d893 083/184: Merge pull request #54 from auto-co
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/popup 871d893 083/184: Merge pull request #54 from auto-complete/use-cl-lib |
Date: |
Wed, 6 Oct 2021 00:01:12 -0400 (EDT) |
branch: elpa/popup
commit 871d89329be8700e877f4a6da9e675a96454c9b1
Merge: a49ffd0 afeaed3
Author: Syohei YOSHIDA <syohex@gmail.com>
Commit: Syohei YOSHIDA <syohex@gmail.com>
Merge pull request #54 from auto-complete/use-cl-lib
Use cl-lib functions instead of cl
---
popup.el | 527 ++++++++++++++++++++++++++++++++-------------------------------
1 file changed, 264 insertions(+), 263 deletions(-)
diff --git a/popup.el b/popup.el
index 5c3af45..f5c9269 100644
--- a/popup.el
+++ b/popup.el
@@ -5,6 +5,7 @@
;; Author: Tomohiro Matsuyama <tomo@cx4a.org>
;; Keywords: lisp
;; Version: 0.5.0
+;; Package-Requires: ((cl-lib "0.3"))
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
@@ -28,7 +29,7 @@
;;; Code:
-(require 'cl)
+(require 'cl-lib)
(defconst popup-version "0.5.0")
@@ -55,7 +56,7 @@ If there is a problem, please set it nil.")
(defun popup-x-to-string (x)
"Convert any object to string effeciently.
This is faster than `prin1-to-string' in many cases."
- (typecase x
+ (cl-typecase x
(string x)
(symbol (symbol-name x))
(integer (number-to-string x))
@@ -67,15 +68,15 @@ This is faster than `prin1-to-string' in many cases."
splitting with WIDTH."
;; Expand tabs into 4 spaces
(setq string (replace-regexp-in-string "\t" " " string))
- (loop with len = (length string)
- with w = 0
- for l from 0
- for c in (append string nil)
- while (<= (incf w (char-width c)) width)
- finally return
- (if (< l len)
- (cons (substring string 0 l) (substring string l))
- (list string))))
+ (cl-loop with len = (length string)
+ with w = 0
+ for l from 0
+ for c in (append string nil)
+ while (<= (incf w (char-width c)) width)
+ finally return
+ (if (< l len)
+ (cons (substring string 0 l) (substring string l))
+ (list string))))
(defun popup-fill-string (string &optional width max-width justify squeeze)
"Split STRING into fixed width strings and return a cons cell
@@ -142,15 +143,15 @@ untouched."
(defun popup-preferred-width (list)
"Return the preferred width to show LIST beautifully."
- (loop with tab-width = 4
- for item in list
- for summary = (popup-item-summary item)
- maximize (string-width (popup-x-to-string item)) into width
- if (stringp summary)
- maximize (+ (string-width summary) 2) into summary-width
- finally return
- (let ((total (+ (or width 0) (or summary-width 0))))
- (* (ceiling (/ total 10.0)) 10))))
+ (cl-loop with tab-width = 4
+ for item in list
+ for summary = (popup-item-summary item)
+ maximize (string-width (popup-x-to-string item)) into width
+ if (stringp summary)
+ maximize (+ (string-width summary) 2) into summary-width
+ finally return
+ (let ((total (+ (or width 0) (or summary-width 0))))
+ (* (ceiling (/ total 10.0)) 10))))
(defun popup-window-full-width-p (&optional window)
"A portable version of `window-full-width-p'."
@@ -241,7 +242,7 @@ buffer."
(propertize " " 'face 'popup-scroll-bar-background-face)
"Background character for scroll-bar.")
-(defstruct popup
+(cl-defstruct popup
point row column width height min-height direction overlays keymap
parent depth
face mouse-face selection-face summary-face
@@ -252,12 +253,12 @@ buffer."
(defun popup-item-propertize (item &rest properties)
"Same as `propertize' except that this avoids overriding
existed value with `nil' property."
- (loop for (k v) on properties by 'cddr
- if v append (list k v) into props
- finally return
- (apply 'propertize
- (popup-x-to-string item)
- props)))
+ (cl-loop for (k v) on properties by 'cddr
+ if v append (list k v) into props
+ finally return
+ (apply 'propertize
+ (popup-x-to-string item)
+ props)))
(defun popup-item-property (item property)
"Same as `get-text-property' except that this returns nil if
@@ -265,16 +266,16 @@ ITEM is not string."
(if (stringp item)
(get-text-property 0 property item)))
-(defun* popup-make-item (name
- &key
- value
- face
- mouse-face
- selection-face
- sublist
- document
- symbol
- summary)
+(cl-defun popup-make-item (name
+ &key
+ value
+ face
+ mouse-face
+ selection-face
+ sublist
+ document
+ symbol
+ summary)
"Utility function to make popup item. See also
`popup-item-propertize'."
(popup-item-propertize name
@@ -316,17 +317,17 @@ ITEM is not string."
(defun popup-item-show-help-with-event-loop (item)
(save-window-excursion
(when (popup-item-show-help-1 item)
- (loop do (clear-this-command-keys)
- for key = (read-key-sequence-vector nil)
- do
- (case (key-binding key)
- ('scroll-other-window
- (scroll-other-window))
- ('scroll-other-window-down
- (scroll-other-window-down nil))
- (t
- (setq unread-command-events (append key unread-command-events))
- (return)))))))
+ (cl-loop do (clear-this-command-keys)
+ for key = (read-key-sequence-vector nil)
+ do
+ (case (key-binding key)
+ ('scroll-other-window
+ (scroll-other-window))
+ ('scroll-other-window-down
+ (scroll-other-window-down nil))
+ (t
+ (setq unread-command-events (append key
unread-command-events))
+ (return)))))))
(defun popup-item-show-help (item &optional persist)
"Display the documentation of ITEM with `display-buffer'. If
@@ -343,7 +344,7 @@ usual."
(popup-set-filtered-list popup list)
(setf (popup-pattern popup) nil)
(setf (popup-original-list popup) list))
-
+
(defun popup-set-filtered-list (popup list)
(let ((offset
(if (> (popup-direction popup) 0)
@@ -374,19 +375,19 @@ usual."
(and (eq (overlay-get overlay 'display) nil)
(eq (overlay-get overlay 'after-string) nil))))
-(defun* popup-set-line-item (popup
- line
- &key
- item
- face
- mouse-face
- margin-left
- margin-right
- scroll-bar-char
- symbol
- summary
- summary-face
- keymap)
+(cl-defun popup-set-line-item (popup
+ line
+ &key
+ item
+ face
+ mouse-face
+ margin-left
+ margin-right
+ scroll-bar-char
+ symbol
+ summary
+ summary-face
+ keymap)
(let* ((overlay (popup-line-overlay popup line))
(content (popup-create-line-string popup (popup-x-to-string item)
:margin-left margin-left
@@ -421,14 +422,14 @@ usual."
scroll-bar-char
postfix))))
-(defun* popup-create-line-string (popup
- string
- &key
- margin-left
- margin-right
- symbol
- summary
- summary-face)
+(cl-defun popup-create-line-string (popup
+ string
+ &key
+ margin-left
+ margin-right
+ symbol
+ summary
+ summary-face)
(let* ((popup-width (popup-width popup))
(summary-width (string-width summary))
(content-width (max
@@ -480,23 +481,23 @@ number at the point."
-1
1)))
-(defun* popup-create (point
- width
- height
- &key
- min-height
- around
- (face 'popup-face)
- mouse-face
- (selection-face face)
- (summary-face 'popup-summary-face)
- scroll-bar
- margin-left
- margin-right
- symbol
- parent
- parent-offset
- keymap)
+(cl-defun popup-create (point
+ width
+ height
+ &key
+ min-height
+ around
+ (face 'popup-face)
+ mouse-face
+ (selection-face face)
+ (summary-face 'popup-summary-face)
+ scroll-bar
+ margin-left
+ margin-right
+ symbol
+ parent
+ parent-offset
+ keymap)
"Create a popup instance at POINT with WIDTH and HEIGHT.
MIN-HEIGHT is a minimal height of the popup. The default value is
@@ -627,9 +628,9 @@ KEYMAP is a keymap that will be put on the popup contents."
(aset overlays
(if (> direction 0) i (- height i 1))
overlay)))
- (loop for p from (- 10000 (* depth 1000))
- for overlay in (nreverse (append overlays nil))
- do (overlay-put overlay 'priority p))
+ (cl-loop for p from (- 10000 (* depth 1000))
+ for overlay in (nreverse (append overlays nil))
+ do (overlay-put overlay 'priority p))
(let ((it (make-popup :point point
:row row
:column column
@@ -678,101 +679,101 @@ KEYMAP is a keymap that will be put on the popup
contents."
(defun popup-draw (popup)
"Draw POPUP."
- (loop with height = (popup-height popup)
- with min-height = (popup-min-height popup)
- with popup-face = (popup-face popup)
- with mouse-face = (popup-mouse-face popup)
- with selection-face = (popup-selection-face popup)
- with summary-face-0 = (popup-summary-face popup)
- with list = (popup-list popup)
- with length = (length list)
- with thum-size = (max (/ (* height height) (max length 1)) 1)
- with page-size = (/ (+ 0.0 (max length 1)) height)
- with scroll-bar = (popup-scroll-bar popup)
- with margin-left = (make-string (if (popup-margin-left-cancel popup) 0
(popup-margin-left popup)) ? )
- with margin-right = (make-string (popup-margin-right popup) ? )
- with symbol = (popup-symbol popup)
- with cursor = (popup-cursor popup)
- with scroll-top = (popup-scroll-top popup)
- with offset = (popup-offset popup)
- with keymap = (popup-keymap popup)
- for o from offset
- for i from scroll-top
- while (< o height)
- for item in (nthcdr scroll-top list)
- for page-index = (* thum-size (/ o thum-size))
- for face = (if (= i cursor)
- (or (popup-item-selection-face item) selection-face)
- (or (popup-item-face item) popup-face))
- for summary-face = (unless (= i cursor) summary-face-0)
- for empty-char = (propertize " " 'face face)
- for scroll-bar-char = (if scroll-bar
- (cond
- ((and (not (eq scroll-bar :always))
- (<= page-size 1))
- empty-char)
- ((and (> page-size 1)
- (>= cursor (* page-index page-size))
- (< cursor (* (+ page-index thum-size)
page-size)))
- popup-scroll-bar-foreground-char)
- (t
- popup-scroll-bar-background-char))
- "")
- for sym = (if symbol
- (concat " " (or (popup-item-symbol item) " "))
- "")
- for summary = (or (popup-item-summary item) "")
-
- do
- ;; Show line and set item to the line
- (popup-set-line-item popup o
- :item item
- :face face
- :mouse-face mouse-face
- :margin-left margin-left
- :margin-right margin-right
- :scroll-bar-char scroll-bar-char
- :symbol sym
- :summary summary
- :summary-face summary-face
- :keymap keymap)
-
- finally
- ;; Remember current height
- (setf (popup-current-height popup) (- o offset))
-
- ;; Hide remaining lines
- (let ((scroll-bar-char (if scroll-bar (propertize " " 'face
popup-face) ""))
- (symbol (if symbol " " "")))
- (if (> (popup-direction popup) 0)
- (progn
- (when min-height
- (while (< o min-height)
- (popup-set-line-item popup o
- :item ""
- :face popup-face
- :margin-left margin-left
- :margin-right margin-right
- :scroll-bar-char scroll-bar-char
- :symbol symbol
- :summary "")
- (incf o)))
- (while (< o height)
- (popup-hide-line popup o)
- (incf o)))
- (loop with h = (if min-height (- height min-height) offset)
- for o from 0 below offset
- if (< o h)
- do (popup-hide-line popup o)
- if (>= o h)
- do (popup-set-line-item popup o
- :item ""
- :face popup-face
- :margin-left margin-left
- :margin-right margin-right
- :scroll-bar-char scroll-bar-char
- :symbol symbol
- :summary ""))))))
+ (cl-loop with height = (popup-height popup)
+ with min-height = (popup-min-height popup)
+ with popup-face = (popup-face popup)
+ with mouse-face = (popup-mouse-face popup)
+ with selection-face = (popup-selection-face popup)
+ with summary-face-0 = (popup-summary-face popup)
+ with list = (popup-list popup)
+ with length = (length list)
+ with thum-size = (max (/ (* height height) (max length 1)) 1)
+ with page-size = (/ (+ 0.0 (max length 1)) height)
+ with scroll-bar = (popup-scroll-bar popup)
+ with margin-left = (make-string (if (popup-margin-left-cancel
popup) 0 (popup-margin-left popup)) ? )
+ with margin-right = (make-string (popup-margin-right popup) ? )
+ with symbol = (popup-symbol popup)
+ with cursor = (popup-cursor popup)
+ with scroll-top = (popup-scroll-top popup)
+ with offset = (popup-offset popup)
+ with keymap = (popup-keymap popup)
+ for o from offset
+ for i from scroll-top
+ while (< o height)
+ for item in (nthcdr scroll-top list)
+ for page-index = (* thum-size (/ o thum-size))
+ for face = (if (= i cursor)
+ (or (popup-item-selection-face item) selection-face)
+ (or (popup-item-face item) popup-face))
+ for summary-face = (unless (= i cursor) summary-face-0)
+ for empty-char = (propertize " " 'face face)
+ for scroll-bar-char = (if scroll-bar
+ (cond
+ ((and (not (eq scroll-bar :always))
+ (<= page-size 1))
+ empty-char)
+ ((and (> page-size 1)
+ (>= cursor (* page-index
page-size))
+ (< cursor (* (+ page-index
thum-size) page-size)))
+ popup-scroll-bar-foreground-char)
+ (t
+ popup-scroll-bar-background-char))
+ "")
+ for sym = (if symbol
+ (concat " " (or (popup-item-symbol item) " "))
+ "")
+ for summary = (or (popup-item-summary item) "")
+
+ do
+ ;; Show line and set item to the line
+ (popup-set-line-item popup o
+ :item item
+ :face face
+ :mouse-face mouse-face
+ :margin-left margin-left
+ :margin-right margin-right
+ :scroll-bar-char scroll-bar-char
+ :symbol sym
+ :summary summary
+ :summary-face summary-face
+ :keymap keymap)
+
+ finally
+ ;; Remember current height
+ (setf (popup-current-height popup) (- o offset))
+
+ ;; Hide remaining lines
+ (let ((scroll-bar-char (if scroll-bar (propertize " " 'face
popup-face) ""))
+ (symbol (if symbol " " "")))
+ (if (> (popup-direction popup) 0)
+ (progn
+ (when min-height
+ (while (< o min-height)
+ (popup-set-line-item popup o
+ :item ""
+ :face popup-face
+ :margin-left margin-left
+ :margin-right margin-right
+ :scroll-bar-char scroll-bar-char
+ :symbol symbol
+ :summary "")
+ (incf o)))
+ (while (< o height)
+ (popup-hide-line popup o)
+ (incf o)))
+ (cl-loop with h = (if min-height (- height min-height) offset)
+ for o from 0 below offset
+ if (< o h)
+ do (popup-hide-line popup o)
+ if (>= o h)
+ do (popup-set-line-item popup o
+ :item ""
+ :face popup-face
+ :margin-left margin-left
+ :margin-right margin-right
+ :scroll-bar-char
scroll-bar-char
+ :symbol symbol
+ :summary ""))))))
(defun popup-hide (popup)
"Hide POPUP."
@@ -895,25 +896,25 @@ Pages up through POPUP."
(<= char 126)))
(defun popup-isearch-filter-list (pattern list)
- (loop with regexp = (regexp-quote pattern)
- for item in list
- do
- (unless (stringp item)
- (setq item (popup-item-propertize (popup-x-to-string item)
- 'value item)))
- if (string-match regexp item)
- collect
- (let ((beg (match-beginning 0))
- (end (match-end 0)))
- (alter-text-property 0 (length item) 'face
- (lambda (prop)
- (unless (eq prop 'popup-isearch-match)
- prop))
- item)
- (put-text-property beg end
- 'face 'popup-isearch-match
- item)
- item)))
+ (cl-loop with regexp = (regexp-quote pattern)
+ for item in list
+ do
+ (unless (stringp item)
+ (setq item (popup-item-propertize (popup-x-to-string item)
+ 'value item)))
+ if (string-match regexp item)
+ collect
+ (let ((beg (match-beginning 0))
+ (end (match-end 0)))
+ (alter-text-property 0 (length item) 'face
+ (lambda (prop)
+ (unless (eq prop 'popup-isearch-match)
+ prop))
+ item)
+ (put-text-property beg end
+ 'face 'popup-isearch-match
+ item)
+ item)))
(defun popup-isearch-prompt (popup pattern)
(format "Pattern: %s" (if (= (length (popup-list popup)) 0)
@@ -930,12 +931,12 @@ Pages up through POPUP."
(funcall callback list)))
(popup-draw popup))
-(defun* popup-isearch (popup
- &key
- (cursor-color popup-isearch-cursor-color)
- (keymap popup-isearch-keymap)
- callback
- help-delay)
+(cl-defun popup-isearch (popup
+ &key
+ (cursor-color popup-isearch-cursor-color)
+ (keymap popup-isearch-keymap)
+ callback
+ help-delay)
"Start isearch on POPUP. This function is synchronized, meaning
event loop waits for quiting of isearch.
@@ -997,23 +998,23 @@ HELP-DELAY is a delay of displaying helps."
(defvar popup-tip-max-width 80)
-(defun* popup-tip (string
- &key
- point
- (around t)
- width
- (height 15)
- min-height
- truncate
- margin
- margin-left
- margin-right
- scroll-bar
- parent
- parent-offset
- nowait
- prompt
- &aux tip lines)
+(cl-defun popup-tip (string
+ &key
+ point
+ (around t)
+ width
+ (height 15)
+ min-height
+ truncate
+ margin
+ margin-left
+ margin-right
+ scroll-bar
+ parent
+ parent-offset
+ nowait
+ prompt
+ &aux tip lines)
"Show a tooltip of STRING at POINT. This function is
synchronized unless NOWAIT specified. Almost arguments are same
as `popup-create' except for TRUNCATE, NOWAIT, and PROMPT.
@@ -1162,17 +1163,17 @@ PROMPT is a prompt string when reading events during
event loop."
(defun popup-menu-fallback (event default))
-(defun* popup-menu-event-loop (menu
- keymap
- fallback
- &key
- prompt
- help-delay
- isearch
- isearch-cursor-color
- isearch-keymap
- isearch-callback
- &aux key binding)
+(cl-defun popup-menu-event-loop (menu
+ keymap
+ fallback
+ &key
+ prompt
+ help-delay
+ isearch
+ isearch-cursor-color
+ isearch-keymap
+ isearch-callback
+ &aux key binding)
(block nil
(while (popup-live-p menu)
(and isearch
@@ -1198,7 +1199,7 @@ PROMPT is a prompt string when reading events during
event loop."
((memq binding '(popup-select popup-open))
(let* ((item (or (popup-menu-item-of-mouse-event (elt key 0))
(popup-selected-item menu)))
- (index (position item (popup-list menu)))
+ (index (cl-position item (popup-list menu)))
(sublist (popup-item-sublist item)))
(unless index (return))
(if sublist
@@ -1234,30 +1235,30 @@ PROMPT is a prompt string when reading events during
event loop."
(t
(funcall fallback key (key-binding key)))))))
-(defun* popup-menu* (list
- &key
- point
- (around t)
- (width (popup-preferred-width list))
- (height 15)
- margin
- margin-left
- margin-right
- scroll-bar
- symbol
- parent
- parent-offset
- cursor
- (keymap popup-menu-keymap)
- (fallback 'popup-menu-fallback)
- help-delay
- nowait
- prompt
- isearch
- (isearch-cursor-color popup-isearch-cursor-color)
- (isearch-keymap popup-isearch-keymap)
- isearch-callback
- &aux menu event)
+(cl-defun popup-menu* (list
+ &key
+ point
+ (around t)
+ (width (popup-preferred-width list))
+ (height 15)
+ margin
+ margin-left
+ margin-right
+ scroll-bar
+ symbol
+ parent
+ parent-offset
+ cursor
+ (keymap popup-menu-keymap)
+ (fallback 'popup-menu-fallback)
+ help-delay
+ nowait
+ prompt
+ isearch
+ (isearch-cursor-color popup-isearch-cursor-color)
+ (isearch-keymap popup-isearch-keymap)
+ isearch-callback
+ &aux menu event)
"Show a popup menu of LIST at POINT. This function returns a
value of the selected item. Almost arguments are same as
`popup-create' except for KEYMAP, FALLBACK, HELP-DELAY, PROMPT,
- [nongnu] elpa/popup f15c82b 014/184: Merge pull request #10 from tkf/inhibit-read-only, (continued)
- [nongnu] elpa/popup f15c82b 014/184: Merge pull request #10 from tkf/inhibit-read-only, ELPA Syncer, 2021/10/06
- [nongnu] elpa/popup 2f1c9d8 056/184: Refactoring: new variable in popup-create-line-string, ELPA Syncer, 2021/10/06
- [nongnu] elpa/popup 6a2520d 040/184: Add folding test case when on the corner, ELPA Syncer, 2021/10/06
- [nongnu] elpa/popup 17a0cd4 080/184: Add :initial-cursor keyword option to popup-menu*., ELPA Syncer, 2021/10/06
- [nongnu] elpa/popup 37c8761 070/184: Refactoring all test cases, ELPA Syncer, 2021/10/06
- [nongnu] elpa/popup 05f5492 069/184: Change buffer-contents from string to propertied string for detecting end of popup., ELPA Syncer, 2021/10/06
- [nongnu] elpa/popup 23652e7 064/184: Use face inheritance to avoid duplication, ELPA Syncer, 2021/10/06
- [nongnu] elpa/popup aa8762f 077/184: Fix travis configuration file for using cl-lib, ELPA Syncer, 2021/10/06
- [nongnu] elpa/popup ca3cc7f 106/184: Add: initial-index keyword argument to function `popup-menu*'. (initial-index argument is optional argument), ELPA Syncer, 2021/10/06
- [nongnu] elpa/popup 4bee35b 128/184: Add screenshot images, ELPA Syncer, 2021/10/06
- [nongnu] elpa/popup 871d893 083/184: Merge pull request #54 from auto-complete/use-cl-lib,
ELPA Syncer <=
- [nongnu] elpa/popup a3d1bfd 112/184: Fix test., ELPA Syncer, 2021/10/06
- [nongnu] elpa/popup a73a3b1 104/184: Fix for using cask, ELPA Syncer, 2021/10/06
- [nongnu] elpa/popup 0f640e0 087/184: remove require because popup already requires it, ELPA Syncer, 2021/10/06
- [nongnu] elpa/popup 33dac62 127/184: Fix MELPA stable link, ELPA Syncer, 2021/10/06
- [nongnu] elpa/popup 982f4ec 108/184: Untabify, ELPA Syncer, 2021/10/06
- [nongnu] elpa/popup 8ca9644 091/184: Delete trailing spaces, ELPA Syncer, 2021/10/06
- [nongnu] elpa/popup 2af1c6c 129/184: Update copyright, ELPA Syncer, 2021/10/06
- [nongnu] elpa/popup 730b408 113/184: Ignore byte-compiled files, ELPA Syncer, 2021/10/06
- [nongnu] elpa/popup 46632ab 134/184: Merge pull request #93 from auto-complete/fix-for-24.5, ELPA Syncer, 2021/10/06
- [nongnu] elpa/popup 91285c2 140/184: Update document about customize variables, ELPA Syncer, 2021/10/06