branch: externals/swiper
commit 404a904f76261b9dceb303b006606f62d3627e65
Merge: 8d339d03a0 847ba97f6b
Author: Basil L. Contovounesios <ba...@contovou.net>
Commit: Basil L. Contovounesios <ba...@contovou.net>

    Merge branch 'master' into externals/swiper
---
 .dir-locals.el  |  13 +++---
 swiper.el       |  44 +++++++++++---------
 targets/elpa.el | 125 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 154 insertions(+), 28 deletions(-)

diff --git a/.dir-locals.el b/.dir-locals.el
index f18455c3a6..9920229883 100644
--- a/.dir-locals.el
+++ b/.dir-locals.el
@@ -2,17 +2,14 @@
 ;;; For more information see (info "(emacs) Directory Variables")
 
 ((nil
-  ;; Emacs 28+ automatically sets up these `bug-reference-mode' variables
-  ;; in a more general way, so setting them here is not future-proof.  If
-  ;; you still need these settings in older Emacs versions, you can add
-  ;; them to your personal `.dir-locals-2.el' file in the meantime.
-  ;; (bug-reference-bug-regexp . "\\(#\\([[:digit:]]+\\)\\)")
-  ;; (bug-reference-url-format . "https://github.com/abo-abo/swiper/issues/%s";)
   (copyright-names-regexp . "Free Software Foundation, Inc\\.")
   (sentence-end-double-space . t))
  (emacs-lisp-mode
   (indent-tabs-mode . nil)
-  (outline-regexp . ";;\\([;*]+ [^\s\t\n]\\|###autoload\\)\\|(")
   ;; extra config here: 
https://github.com/abo-abo/oremacs/blob/github/modes/ora-elisp-style-guide.el
   ;; (lisp-indent-function . common-lisp-indent-function)
-  ))
+  )
+ (markdown-mode
+  (fill-column . 70))
+ (org-mode
+  (fill-column . 70)))
diff --git a/swiper.el b/swiper.el
index edeee0e995..bbe05a992d 100644
--- a/swiper.el
+++ b/swiper.el
@@ -155,12 +155,12 @@ If the input is empty, select the previous history 
element instead."
 
 (defvar swiper-map
   (let ((map (make-sparse-keymap)))
-    (define-key map (kbd "C-s") 'swiper-C-s)
-    (define-key map (kbd "M-q") 'swiper-query-replace)
-    (define-key map (kbd "C-l") 'swiper-recenter-top-bottom)
-    (define-key map (kbd "C-'") 'swiper-avy)
-    (define-key map (kbd "C-7") 'swiper-mc)
-    (define-key map (kbd "C-c C-f") 'swiper-toggle-face-matching)
+    (define-key map (kbd "C-s") #'swiper-C-s)
+    (define-key map (kbd "M-q") #'swiper-query-replace)
+    (define-key map (kbd "C-l") #'swiper-recenter-top-bottom)
+    (define-key map (kbd "C-'") #'swiper-avy)
+    (define-key map (kbd "C-7") #'swiper-mc)
+    (define-key map (kbd "C-c C-f") #'swiper-toggle-face-matching)
     map)
   "Keymap for swiper.")
 
@@ -247,7 +247,7 @@ If the input is empty, select the previous history element 
instead."
 
 (ivy-configure 'swiper-query-replace
   :update-fn #'swiper--query-replace-updatefn)
-(put 'swiper-query-replace 'no-counsel-M-x t)
+(function-put #'swiper-query-replace 'no-counsel-M-x t)
 
 (defvar inhibit-message)
 
@@ -272,7 +272,7 @@ If the input is empty, select the previous history element 
instead."
                     (goto-char (point-min))
                     (perform-replace from to t t nil)))
              (set-window-configuration wnd-conf))))))))
-(put 'swiper-all-query-replace 'no-counsel-M-x t)
+(function-put #'swiper-all-query-replace 'no-counsel-M-x t)
 
 (defvar avy-all-windows)
 (defvar avy-style)
@@ -481,7 +481,7 @@ such as `scroll-conservatively' are set to a high value.")
   "List of major-modes that are incompatible with `font-lock-ensure'.")
 
 (defun swiper-font-lock-ensure-p ()
-  "Return non-nil if we should `font-lock-ensure'."
+  "Return non-nil if we should not `font-lock-ensure'."
   (or (derived-mode-p 'magit-mode)
       (bound-and-true-p magit-blame-mode)
       (memq major-mode swiper-font-lock-exclude)
@@ -489,12 +489,13 @@ such as `scroll-conservatively' are set to a high value.")
 
 (defun swiper-font-lock-ensure ()
   "Ensure the entire buffer is highlighted."
-  (unless (swiper-font-lock-ensure-p)
-    (unless (or (> (buffer-size) 100000) (null font-lock-mode))
-      (if (fboundp 'font-lock-ensure)
-          ;; Added in Emacs 25.1.
-          (font-lock-ensure)
-        (with-no-warnings (font-lock-fontify-buffer))))))
+  (unless (or (swiper-font-lock-ensure-p)
+              (> (buffer-size) 100000)
+              (not font-lock-mode))
+    (static-if (fboundp 'font-lock-ensure)
+        ;; Added in Emacs 25.1.
+        (font-lock-ensure)
+      (font-lock-fontify-buffer))))
 
 (defvar swiper--format-spec ""
   "Store the current candidates format spec.")
@@ -1085,7 +1086,7 @@ WND, when specified is the window."
 (defvar evil-ex-search-pattern)
 (defvar evil-ex-search-persistent-highlight)
 (defvar evil-ex-search-direction)
-(declare-function evil-ex-search-activate-highlight "evil-ex")
+(declare-function evil-ex-search-activate-highlight "ext:evil-search")
 
 (defun swiper--maybe-recenter ()
   (cond (swiper-action-recenter
@@ -1259,8 +1260,9 @@ otherwise continue prompting for buffers."
       ((eq mode 'gnus-article-mode) t)
       ;; Otherwise, only consider the file if it's backed by a file.
       (t (buffer-file-name buffer)))))
+
+;;; `swiper-all'
 
-;;* `swiper-all'
 (defun swiper-all-function (str)
   "Search in all open buffers for STR."
   (or
@@ -1331,7 +1333,7 @@ See `ivy-format-functions-alist' for further information."
 
 (defvar swiper-all-map
   (let ((map (make-sparse-keymap)))
-    (define-key map (kbd "M-q") 'swiper-all-query-replace)
+    (define-key map (kbd "M-q") #'swiper-all-query-replace)
     map)
   "Keymap for `swiper-all'.")
 
@@ -1379,8 +1381,9 @@ See `ivy-format-functions-alist' for further information."
                 (swiper--candidates 4))
                res))))
     res))
+
+;;; `swiper-isearch'
 
-;;* `swiper-isearch'
 (defun swiper-isearch-function (str)
   "Collect STR matches in the current buffer for `swiper-isearch'."
   (with-ivy-window
@@ -1616,7 +1619,8 @@ When the input is empty, browse the search history 
instead."
 (defvar swiper-isearch-map
   (let ((map (make-sparse-keymap)))
     (set-keymap-parent map swiper-map)
-    (define-key map [remap ivy-insert-current] 
#'swiper--isearch-insert-current)
+    (define-key map `[remap ,#'ivy-insert-current]
+                #'swiper--isearch-insert-current)
     (define-key map (kbd "M-n") #'swiper-isearch-thing-at-point)
     (define-key map (kbd "C-r") #'swiper-isearch-C-r)
     map)
diff --git a/targets/elpa.el b/targets/elpa.el
new file mode 100644
index 0000000000..e80dc6a981
--- /dev/null
+++ b/targets/elpa.el
@@ -0,0 +1,125 @@
+;;; targets/elpa.el --- Optional Ivy dependencies -*- lexical-binding: t -*-
+
+;; Copyright (C) 2019-2025 Free Software Foundation, Inc.
+
+;; 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
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+;;; Code:
+
+(require 'package)
+
+(defvar ivy--elpa-stable
+  (or (getenv "ELPA_STABLE")
+      (getenv "MELPA_STABLE"))
+  "Non-nil if GNU ELPA should be used instead of GNU-devel ELPA.")
+
+(defvar ivy--elpa-dir "~/.elpa"
+  "Parent directory for installing optional dependencies.")
+
+(defvar ivy--elpa-user-dir
+  (expand-file-name
+   (format "%s%s/elpa" emacs-version (if ivy--elpa-stable "-stable" ""))
+   ivy--elpa-dir)
+  "Instance-specific value for `package-user-dir'.")
+
+;; FIXME: Switch to `gnu' once https://bugs.gnu.org/76264 is resolved.
+(defvar ivy--elpa-archive 'melpa
+  "Preferred ELPA archive; keys `ivy--elpa-archives'.")
+
+(defvar ivy--elpa-archives
+  ;; Check default value rather than `gnutls-available-p': even when
+  ;; the latter is non-nil my Emacs 24.5 fails with https://.
+  (let ((s (if (string-prefix-p "https" (cdar package-archives)) "s" "")))
+    `((gnu
+       ("gnu" . ,(format "http%s://elpa.gnu.org/%s/"
+                         s (if ivy--elpa-stable "packages" "devel")))
+       ;; For `wgrep'.
+       ("nongnu" . ,(format "http%s://elpa.nongnu.org/nongnu%s/"
+                            s (if ivy--elpa-stable "" "-devel"))))
+      (melpa
+       ("melpa" . ,(format "https://%smelpa.org/packages/";
+                           (if ivy--elpa-stable "stable." ""))))))
+  "Map ELPA archive symbols to their `package-archives'.")
+
+(defvar ivy--elpa-pkgs
+  '(avy
+    hydra
+    wgrep)
+  "List of optional (or development) package dependencies.")
+
+(defvar ivy--elpa-activated nil
+  "Non-nil if `ivy--elpa-activate' succeeded.")
+
+(defvar ivy--elpa-refreshed nil
+  "Non-nil if `ivy--elpa-refresh' succeeded.")
+
+(defun ivy--elpa-activate ()
+  "Ensure packages under `ivy--elpa-dir' are activated."
+  (unless ivy--elpa-activated
+    (setq package-user-dir ivy--elpa-user-dir)
+    (let ((msg (format "Activating packages in %s" package-user-dir)))
+      (message "%s..." msg)
+      (package-initialize)
+      (message "%s...done" msg))
+    (setq ivy--elpa-activated t)))
+
+(defun ivy--elpa-refresh ()
+  "Ensure archive contents are refreshed."
+  (defvar gnutls-algorithm-priority)
+  (unless ivy--elpa-refreshed
+    (let ((archive ivy--elpa-archive))
+      (setq package-archives (cdr (assq archive ivy--elpa-archives)))
+      (and (eq archive 'melpa)
+           (version< emacs-version "26.3")
+           ;; See https://melpa.org/#/getting-started.
+           (setq gnutls-algorithm-priority "NORMAL:-VERS-TLS1.3")))
+    (package-refresh-contents)
+    (setq ivy--elpa-refreshed (and package-archive-contents t))))
+
+(defun ivy--elpa-install-pkg (pkg)
+  "Compatibility shim for Emacs 25 `package-install'."
+  (condition-case nil
+      (package-install pkg t)
+    (wrong-number-of-arguments
+     (package-install pkg))))
+
+(defun ivy--elpa-install ()
+  "Install any missing `ivy--elpa-pkgs' with demoted errors."
+  (ivy--elpa-activate)
+  (ivy--elpa-refresh)
+  (let ((msg-all (format "Installing in %s" package-user-dir))
+        any-ok any-err)
+    (message "%s..." msg-all)
+    (dolist (pkg ivy--elpa-pkgs)
+      (unless (package-installed-p pkg)
+        (let ((msg (format "Installing %s" pkg))
+              err)
+          (message "%s..." msg)
+          (condition-case-unless-debug e
+              (ivy--elpa-install-pkg pkg)
+            (error (message "Error: %s" (error-message-string e))
+                   (message "%s...INCOMPLETE" msg)
+                   (setq any-err t)
+                   (setq err e)))
+          (unless err
+            (message "%s...done" msg)
+            (setq any-ok t)))))
+    (message "%s...%s" msg-all
+             (cond (any-err "INCOMPLETE")
+                   (any-ok "done")
+                   (t "already present")))))
+
+;; TODO: upgrade-deps target?
+
+(provide 'targets/elpa)

Reply via email to