[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

wrap-search 2.1.4

From: Emanuel Berg
Subject: wrap-search 2.1.4
Date: Thu, 02 Jun 2022 03:30:18 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

New version of this program that I used more times (I think)
than every other program I ever wrote, combined. (It says its
from 2021-05-23, that refers to the package tho, actually it's

In 2.1.4, it does regions as well.

Will there ever be another version? I don't know, maybe 3D
search is a feature that's lacking?

;;; wrap-search.el --- wrapped, non-incremental search -*- lexical-binding: t 
;;; Commentary:
;; Author: Emanuel Berg (incal) <>
;; Created: 2021-05-23
;; Keywords: matching
;; License: GPL3+
;; Package-Requires: ((cl-lib "1.0"))
;; URL:
;; Version: 2.1.4
;; The `wrap-search' package offers non-incremental, search -
;; it shows hitss (hits and only hits).
;; `wrap-search' searches forward by default, but it wraps
;; and continues up and until the search start position if
;; necessary. This is so one doesn't have to wonder if the
;; target is north or south in the buffer.
;; The philosophy is that `wrap-search' mostly shouldn't be
;; used for searching - which is possible as well, of course,
;; using the same commands - rather, it is used to quickly
;; _navigate_ a buffer.
;; To use the package without keyboard shortcuts isn't
;; recommended. Instead, do for example
;;   (global-set-key "\C-s" #'wrap-search)
;;   (global-set-key "\C-r" #'wrap-search-again)
;;; Code:

(require 'cl-lib)

(defun wrap-search-again ()
  "Repeat the previous `wrap-search'.

Do a new `wrap-search' with \\[wrap-search]"
  (let ((cmd (cl-find-if (lambda (c)
                           (and (eq (car c) #'wrap-search)
                                (not (string= (nth 1 c) "")) ))
                         command-history) ))
    (if cmd
        (eval cmd)
      (message "no previous search") )))

(defun wrap-search (str &optional case rev beg end)
  "Search for STR.

With CASE the search is case-sensitive.
With REV the search direction is reversed, i.e. north in the buffer from point.
BEG and END, or a region, delimits the search area. (default: whole buffer)

Interactively, \\[universal-argument] once sets CASE
\\[universal-argument] twice sets REV
\\[universal-argument] thrice sets CASE and REV.

Do \\[wrap-search-again] to repeat, with `wrap-search-again'."
   (list (read-string "search: [repeat] ")
         (or (equal current-prefix-arg '( 4))
             (equal current-prefix-arg '(64)) )
         (or (equal current-prefix-arg '(16))
             (equal current-prefix-arg '(64)) )
         (if (use-region-p)
           (point-min) )
         (if (use-region-p)
           (point-max) )))
  (if (string= "" str)
    (let*((case-fold-search (not case))
          (pos (point))
          (search-f (if rev
                      #'search-forward) )
          (search-beg (if rev
                        beg) )
          (search-end (if rev
                        end) ))
      (if (apply (list search-f str search-end t))
          (message "hit: %s" (point))
        (goto-char search-beg)
        (if (apply (list search-f str (+ pos (if rev 0 (length str))) t))
            (if (= pos (point))
                (message "this is the one occurrence")
              (message "hit: %s (wrap)" (point)))
          (goto-char pos)
          (message "no hit") )))))

(provide 'wrap-search)
;;; wrap-search.el ends here

underground experts united

reply via email to

[Prev in Thread] Current Thread [Next in Thread]