Skip to content

Commit

Permalink
Merge branch 'devel' of github.com:jaalto/project--emacs-tiny-tools i…
Browse files Browse the repository at this point in the history
…nto devel
  • Loading branch information
jaalto committed Apr 1, 2014
2 parents 1fb04e3 + 6417cc0 commit 30e0a8d
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 84 deletions.
7 changes: 7 additions & 0 deletions lisp/ChangeLog
@@ -1,3 +1,10 @@
2013-11-27 Wed Jari Aalto <jari.aalto@tamk.fi>

* tiny/tinysearch.el: Remove folding. Remove function headers.
(tinysearch-function-ours-p): New.
(tinysearch-install-default-keybindings): check binding name before
displaying messages.

2013-09-07 Sat Jari Aalto <jari.aalto@cante.net>

* tiny/tinymacro.el:
Expand Down
9 changes: 4 additions & 5 deletions lisp/tiny/tinylibt.el
Expand Up @@ -166,7 +166,6 @@
;; (beginning-of-line)
;; (ti::text-looking-at ".*"))
;; (end-of-line))))
;;

;;; Change Log:

Expand Down Expand Up @@ -557,10 +556,10 @@ Return:
nil No match
nbr start of match at LEVEL."
(let* ((func (if direction
're-search-backward
're-search-forward))
(start-point (point))
(let* ((func (if direction
're-search-backward
're-search-forward))
(start-point (point))
buffer-read-only
max-level
count
Expand Down
127 changes: 48 additions & 79 deletions lisp/tiny/tinysearch.el
Expand Up @@ -8,8 +8,6 @@
;; Keywords: tools
;; Author: Jari Aalto
;; Maintainer: Jari Aalto
;;
;; Look at the code with folding.el.

;; COPYRIGHT NOTICE
;;
Expand All @@ -28,11 +26,8 @@
;;
;; Visit <http://www.gnu.org/copyleft/gpl.html> for more information

;;}}}
;;{{{ Install

;;; Intallation:
;; ....................................................... &t-install ...

;; Put this file on your Emacs-Lisp `load-path', add following into
;; ~/.emacs startup file.
;;
Expand All @@ -50,7 +45,6 @@
;;}}}
;;{{{ Documentation

;; ..................................................... &t-commentary ...
;;; Commentary:

;; Preface, 1994
Expand Down Expand Up @@ -106,7 +100,7 @@
;; find word a boundary:
;;
;; nonWordWORDnonWord
;; ======= =======
;; ======= =======
;;
;; And as you can see, the if ':' belongs to word, it can't
;; simultaneously belong to NonWord ! Summa summarum: Revert to
Expand Down Expand Up @@ -149,46 +143,36 @@
;; Needless to say, that you can use put your own checking
;; function in that variable to control the accurrances better.

;;}}}

;;; Change Log:

;;; Code:

;;{{{ setup: require

(require 'tinylibm)

(ti::package-defgroup-tiny TinySearch tinysearch-- extensions
"search word under cursor: backward, forward.")

;;}}}
;;{{{ hooks

;;; ......................................................... &v-hooks ...

(defcustom tinysearch--before-hook nil
"*Hook that is run at the BEG of search function.
"Hook that is run at the BEG of search function.
You can set this to point to function that alters the value of
`tinysearch--word-boundary-set' e.g. by looking at the file type."
:type 'hook
:group 'TinySearch)

(defcustom tinysearch--final-hook nil
"*Hook that is _always_ run at the END of search function.
"Hook that is _always_ run at the END of search function.
It doesn't care about word grabbings or search failures."
:type 'hook
:group 'TinySearch)

(defcustom tinysearch--load-hook nil
"*Run when package has been loaded.
"Run when package has been loaded.
A good candidate could be `tinysearch-install-default-keybindings'."
:type 'hook
:group 'TinySearch)

;;}}}
;;{{{ variables

;;; ....................................................... &v-private ...

(defvar tinysearch--direction nil
Expand All @@ -205,7 +189,7 @@ Created and killed during program execution.")
;;; User configurable

(defcustom tinysearch--word-boundary-set "-A-Za-z0-9_"
"*Character set to conform a single word."
"Character set to conform a single word."
:type 'hook
:group 'TinySearch)

Expand All @@ -219,12 +203,12 @@ to supply character set to `tinysearch-search-word-main'."
:group 'TinySearch)

(defcustom tinysearch--wrap-flag nil
"*Non-nil means wrap buffer if there is no more match."
"Non-nil means wrap buffer if there is no more match."
:type 'boolean
:group 'TinySearch)

(defcustom tinysearch--accept-word-function 'tinysearch-accept-word
"*Function run after the search for word has been successful.
"Function run after the search for word has been successful.
If this variable contains non-existing function (like nil), the
content of the variable is ignored.
Expand All @@ -243,14 +227,8 @@ Return values of function:
:type 'function
:group 'TinySearch)

;;}}}

;;; ########################################################### &Funcs ###

;;{{{ 19.xx isearch add
;;; ####################################################### &Functions ###

;;; ----------------------------------------------------------------------
;;;
(defun tinysearch-add-to-isearch-search-ring (isearch-string)
"Add search pattern to ISEARCH-STRING in Emacs.
This code is directly taken from function `isearch-done' By Daniel LaLiberte."
Expand All @@ -272,16 +250,11 @@ This code is directly taken from function `isearch-done' By Daniel LaLiberte."
(if (> (length search-ring) search-ring-max)
(setcdr (nthcdr (1- search-ring-max) search-ring) nil)))))))

;;}}}
;;{{{ main

;;; ----------------------------------------------------------------------
;;;
(defun tinysearch-accept-word (word)
"Determine if we accept searched WORD."
(let ((type (symbol-name major-mode))
(ret t) ;default, accept search
space-word)
(ret t) ;default, accept search
space-word)
(cond
((string-match "^c-\\|^cc-\\|c[+]+" type)
;; Check C/C++ dependent variables, where rg. 'a' is
Expand All @@ -299,25 +272,23 @@ This code is directly taken from function `isearch-done' By Daniel LaLiberte."
(setq ret nil))))
ret))

;;; ----------------------------------------------------------------------
;;;
(defun tinysearch-grab-word (&optional charset beg end )
"Gets word under cursor limited by CHARSET string.
Optional BEG and END gives maximum search limits.
Default boundary is line limit."
(let (re-word-boundary
re-word
;; Accept ':' and '-' , beasuse they are used in c++ and lisp
(charset (or charset "--A-Za-z0-9_"))
pb
pe
p
re
ret)
re-word
;; Accept ':' and '-' , beasuse they are used in c++ and lisp
(charset (or charset "--A-Za-z0-9_"))
pb
pe
p
re
ret)
(or beg
(setq beg (line-beginning-position)))
(setq beg (line-beginning-position)))
(or end
(setq end (line-end-position)))
(setq end (line-end-position)))
(setq re-word-boundary (concat "[^" charset "]"))
(setq re-word (concat "[" charset "]")) ;considered single word
;; Note: the first search goes backwards to find the start of the
Expand Down Expand Up @@ -348,7 +319,6 @@ Default boundary is line limit."
;; easier to debug this way
ret))

;;; ----------------------------------------------------------------------
;;; - There is lot of re-search-backward/fwd commands and it is intentional,
;;; so that the code is completely Emacs version independent.
;;; - FIXME: Newer emacs has nice functions that could shrink this code
Expand Down Expand Up @@ -472,12 +442,10 @@ NOTE:
(if tinysearch--final-hook
(run-hooks 'tinysearch--final-hook))))

;;; ----------------------------------------------------------------------
;;;
(defun tinysearch-charset-control ()
"Dynamic character set change according to mode."
(let ((type (symbol-name major-mode))
set)
set)
(cond
((string-match "^c-\\|^cc-\\|c[+]+|perl|python|ruby" type)
(setq set "A-Za-z0-9_"))
Expand All @@ -486,8 +454,6 @@ NOTE:
(setq set "--A-Za-z0-9_")))
set))

;;; ----------------------------------------------------------------------
;;;
;;;###autoload
(defun tinysearch-search-word-forward ()
"Search word at point forward."
Expand All @@ -497,8 +463,6 @@ NOTE:
(if (functionp tinysearch--word-boundary-function)
(funcall tinysearch--word-boundary-function))))

;;; ----------------------------------------------------------------------
;;;
;;;###autoload
(defun tinysearch-search-word-backward ()
"Search word at point backward."
Expand All @@ -508,8 +472,11 @@ NOTE:
(if (functionp tinysearch--word-boundary-function)
(funcall tinysearch--word-boundary-function))))

;;; ----------------------------------------------------------------------
;;;
(defun tinysearch-function-ours-p (function)
"Check if FUNCTION if defined in the package."
(when (symbolp function)
(string-match "^tinysearch" (symbol-name function))))

;;;###autoload
(defun tinysearch-install-default-keybindings ()
"Install default keybindings.
Expand All @@ -518,37 +485,39 @@ C-M-Mouse-1 M-r reverse."
(interactive)
(let (key)
;; In Emacs 23+ these are no longer available
(if (setq key (lookup-key global-map "\M-s"))
(message "** Tinysearch: Can't bind. Key M-s already occupied: %s"
key)
(if (and (setq key (lookup-key global-map "\M-s"))
(not (tinysearch-function-ours-p key)))
(message "** Tinysearch: Can't bind. Key M-s already occupied: %s"
key)
(global-set-key "\M-s" 'tinysearch-search-word-forward))
(if (setq key (lookup-key global-map "\M-s"))
(message "** Tinysearch: Can't bind. Key M-r already occupied: %s"
key)
(if (and (setq key (lookup-key global-map "\M-s"))
(not (tinysearch-function-ours-p key)))
(message "** Tinysearch: Can't bind. Key M-r already occupied: %s"
key)
(global-set-key "\M-r" 'tinysearch-search-word-backward))
;; For mouse (under windowed system)
(if (setq key (lookup-key global-map [(meta control mouse-1)]))
(message "** Tinysearch: Can't bind. M-C-mouse-1 already occupied: %s"
key)
(if (and (setq key (lookup-key global-map
[(meta control mouse-1)]))
(not (tinysearch-function-ours-p key)))
(message "** Tinysearch: Can't bind. M-C-mouse-1 already occupied: %s"
key)
(global-set-key [(meta control mouse-1)]
'tinysearch-search-word-forward))
(if (setq key (lookup-key global-map [(meta control shift mouse-1)]))
(message
"** Tinysearch: Can't bind. M-C-S-mouse-1 already occupied: %s"
key)
'tinysearch-search-word-forward))
(if (and (setq key (lookup-key global-map
[(meta control shift mouse-1)]))
(not (tinysearch-function-ours-p key)))
(message
"** Tinysearch: Can't bind. M-C-S-mouse-1 already occupied: %s"
key)
(global-set-key [(meta control shift mouse-1)]
'tinysearch-search-word-backward))))
'tinysearch-search-word-backward))))

;;; ----------------------------------------------------------------------
;;;
;;;###autoload
(defun tinysearch-install (&optional arg)
"Call `tinysearch-install-default-keybindings' with ARG."
(interactive)
(tinysearch-install-default-keybindings arg))

;;}}}

(provide 'tinysearch)
(run-hooks 'tinysearch--load-hook)

Expand Down

0 comments on commit 30e0a8d

Please sign in to comment.