Renamed link.el

* lisp/net/link.el: Renamed to connection-link.el, also prefixing all
functions with "dictionary-" prefix
* lisp/net/dictionary.el: Adapt to renamed functions
This commit is contained in:
Torsten Hilbrich 2020-10-05 07:11:25 +02:00
parent 658ec3ccee
commit e2ebffdd62
2 changed files with 71 additions and 74 deletions

View file

@ -1,4 +1,4 @@
;;; link.el --- Hypertext links in text buffers ;;; dictionary-link.el --- Hypertext links in text buffers
;; Author: Torsten Hilbrich <torsten.hilbrich@gmx.net> ;; Author: Torsten Hilbrich <torsten.hilbrich@gmx.net>
;; Keywords: interface, hypermedia ;; Keywords: interface, hypermedia
@ -31,15 +31,12 @@
;; argument. Both the function and the data are stored in text ;; argument. Both the function and the data are stored in text
;; properties. ;; properties.
;; ;;
;; link-create-link - insert a new link for the text in the given range ;; dictionary-link-create-link - insert a new link for the text in the given range
;; link-initialize-keymap - install the keybinding for selecting links ;; dictionary-link-initialize-keymap - install the keybinding for selecting links
;;; Code: ;;; Code:
(eval-when-compile (defun dictionary-link-create-link (start end face function &optional data help)
(require 'cl))
(defun link-create-link (start end face function &optional data help)
"Create a link in the current buffer starting from `start' going to `end'. "Create a link in the current buffer starting from `start' going to `end'.
The `face' is used for displaying, the `data' are stored together with the The `face' is used for displaying, the `data' are stored together with the
link. Upon clicking the `function' is called with `data' as argument." link. Upon clicking the `function' is called with `data' as argument."
@ -52,15 +49,15 @@ link. Upon clicking the `function' is called with `data' as argument."
(remove-text-properties start end properties) (remove-text-properties start end properties)
(add-text-properties start end properties))) (add-text-properties start end properties)))
(defun link-insert-link (text face function &optional data help) (defun dictionary-link-insert-link (text face function &optional data help)
"Insert the `text' at point to be formatted as link. "Insert the `text' at point to be formatted as link.
The `face' is used for displaying, the `data' are stored together with the The `face' is used for displaying, the `data' are stored together with the
link. Upon clicking the `function' is called with `data' as argument." link. Upon clicking the `function' is called with `data' as argument."
(let ((start (point))) (let ((start (point)))
(insert text) (insert text)
(link-create-link start (point) face function data help))) (dictionary-link-create-link start (point) face function data help)))
(defun link-selected (&optional all) (defun dictionary-link-selected (&optional all)
"Is called upon clicking or otherwise visiting the link." "Is called upon clicking or otherwise visiting the link."
(interactive) (interactive)
@ -70,26 +67,26 @@ link. Upon clicking the `function' is called with `data' as argument."
(if function (if function
(funcall function data all)))) (funcall function data all))))
(defun link-selected-all () (defun dictionary-link-selected-all ()
"Called for meta clicking the link" "Called for meta clicking the link"
(interactive) (interactive)
(link-selected 'all)) (dictionary-link-selected 'all))
(defun link-mouse-click (event &optional all) (defun dictionary-link-mouse-click (event &optional all)
"Is called upon clicking the link." "Is called upon clicking the link."
(interactive "@e") (interactive "@e")
(mouse-set-point event) (mouse-set-point event)
(link-selected)) (dictionary-link-selected))
(defun link-mouse-click-all (event) (defun dictionary-link-mouse-click-all (event)
"Is called upon meta clicking the link." "Is called upon meta clicking the link."
(interactive "@e") (interactive "@e")
(mouse-set-point event) (mouse-set-point event)
(link-selected-all)) (dictionary-link-selected-all))
(defun link-next-link () (defun dictionary-link-next-link ()
"Return the position of the next link or nil if there is none" "Return the position of the next link or nil if there is none"
(let* ((pos (point)) (let* ((pos (point))
(pos (next-single-property-change pos 'link))) (pos (next-single-property-change pos 'link)))
@ -100,7 +97,7 @@ link. Upon clicking the `function' is called with `data' as argument."
nil))) nil)))
(defun link-prev-link () (defun dictionary-link-prev-link ()
"Return the position of the previous link or nil if there is none" "Return the position of the previous link or nil if there is none"
(let* ((pos (point)) (let* ((pos (point))
(pos (previous-single-property-change pos 'link))) (pos (previous-single-property-change pos 'link)))
@ -113,17 +110,17 @@ link. Upon clicking the `function' is called with `data' as argument."
(text-property-any (point-min) (1+ (point-min)) 'link t)))) (text-property-any (point-min) (1+ (point-min)) 'link t))))
nil))) nil)))
(defun link-initialize-keymap (keymap) (defun dictionary-link-initialize-keymap (keymap)
"Defines the necessary bindings inside keymap" "Defines the necessary bindings inside keymap"
(if (and (boundp 'running-xemacs) running-xemacs) (if (and (boundp 'running-xemacs) running-xemacs)
(progn (progn
(define-key keymap [button2] 'link-mouse-click) (define-key keymap [button2] 'dictionary-link-mouse-click)
(define-key keymap [(meta button2)] 'link-mouse-click-all)) (define-key keymap [(meta button2)] 'dictionary-link-mouse-click-all))
(define-key keymap [mouse-2] 'link-mouse-click) (define-key keymap [mouse-2] 'dictionary-link-mouse-click)
(define-key keymap [M-mouse-2] 'link-mouse-click-all)) (define-key keymap [M-mouse-2] 'dictionary-link-mouse-click-all))
(define-key keymap "\r" 'link-selected) (define-key keymap "\r" 'dictionary-link-selected)
(define-key keymap "\M-\r" 'link-selected-all)) (define-key keymap "\M-\r" 'dictionary-link-selected-all))
(provide 'link) (provide 'dictionary-link)
;;; link.el ends here ;;; dictionary-link.el ends here

View file

@ -40,7 +40,7 @@
(require 'easymenu) (require 'easymenu)
(require 'custom) (require 'custom)
(require 'dictionary-connection) (require 'dictionary-connection)
(require 'link) (require 'dictionary-link)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Stuff for customizing. ;; Stuff for customizing.
@ -434,7 +434,7 @@ by the choice value:
(define-key dictionary-mode-map " " 'scroll-up) (define-key dictionary-mode-map " " 'scroll-up)
(define-key dictionary-mode-map [(meta space)] 'scroll-down) (define-key dictionary-mode-map [(meta space)] 'scroll-down)
(link-initialize-keymap dictionary-mode-map)) (dictionary-link-initialize-keymap dictionary-mode-map))
(defmacro dictionary-reply-code (reply) (defmacro dictionary-reply-code (reply)
"Return the reply code stored in `reply'." "Return the reply code stored in `reply'."
@ -713,34 +713,34 @@ This function knows about the special meaning of quotes (\")"
(erase-buffer) (erase-buffer)
(if dictionary-create-buttons (if dictionary-create-buttons
(progn (progn
(link-insert-link "[Back]" 'dictionary-button-face (dictionary-link-insert-link "[Back]" 'dictionary-button-face
'dictionary-restore-state nil 'dictionary-restore-state nil
"Mouse-2 to go backwards in history") "Mouse-2 to go backwards in history")
(insert " ") (insert " ")
(link-insert-link "[Search Definition]" (dictionary-link-insert-link "[Search Definition]"
'dictionary-button-face 'dictionary-button-face
'dictionary-search nil 'dictionary-search nil
"Mouse-2 to look up a new word") "Mouse-2 to look up a new word")
(insert " ") (insert " ")
(link-insert-link "[Matching words]" (dictionary-link-insert-link "[Matching words]"
'dictionary-button-face 'dictionary-button-face
'dictionary-match-words nil 'dictionary-match-words nil
"Mouse-2 to find matches for a pattern") "Mouse-2 to find matches for a pattern")
(insert " ") (insert " ")
(link-insert-link "[Quit]" 'dictionary-button-face (dictionary-link-insert-link "[Quit]" 'dictionary-button-face
'dictionary-close nil 'dictionary-close nil
"Mouse-2 to close this window") "Mouse-2 to close this window")
(insert "\n ") (insert "\n ")
(link-insert-link "[Select Dictionary]" (dictionary-link-insert-link "[Select Dictionary]"
'dictionary-button-face 'dictionary-button-face
'dictionary-select-dictionary nil 'dictionary-select-dictionary nil
"Mouse-2 to select dictionary for future searches") "Mouse-2 to select dictionary for future searches")
(insert " ") (insert " ")
(link-insert-link "[Select Match Strategy]" (dictionary-link-insert-link "[Select Match Strategy]"
'dictionary-button-face 'dictionary-button-face
'dictionary-select-strategy nil 'dictionary-select-strategy nil
"Mouse-2 to select matching algorithm") "Mouse-2 to select matching algorithm")
@ -821,7 +821,7 @@ The word is taken from the buffer, the `dictionary' is given as argument."
(setq word (replace-match "" t t word))) (setq word (replace-match "" t t word)))
(unless (equal word displayed-word) (unless (equal word displayed-word)
(link-create-link start end 'dictionary-reference-face (dictionary-link-create-link start end 'dictionary-reference-face
call (cons word dictionary) call (cons word dictionary)
(concat "Press Mouse-2 to lookup \"" (concat "Press Mouse-2 to lookup \""
word "\" in \"" dictionary "\""))))) word "\" in \"" dictionary "\"")))))
@ -882,7 +882,7 @@ If PATTERN is omitted, it defaults to \"[ \\f\\t\\n\\r\\v]+\"."
(if dictionary (if dictionary
(if (equal dictionary "--exit--") (if (equal dictionary "--exit--")
(insert "(end of default search list)\n") (insert "(end of default search list)\n")
(link-insert-link (concat dictionary ": " translated) (dictionary-link-insert-link (concat dictionary ": " translated)
'dictionary-reference-face 'dictionary-reference-face
'dictionary-set-dictionary 'dictionary-set-dictionary
(cons dictionary description) (cons dictionary description)
@ -918,7 +918,7 @@ If PATTERN is omitted, it defaults to \"[ \\f\\t\\n\\r\\v]+\"."
(error "Unknown server answer: %s" (dictionary-reply reply))) (error "Unknown server answer: %s" (dictionary-reply reply)))
(dictionary-pre-buffer) (dictionary-pre-buffer)
(insert "Information on dictionary: ") (insert "Information on dictionary: ")
(link-insert-link description 'dictionary-reference-face (dictionary-link-insert-link description 'dictionary-reference-face
'dictionary-set-dictionary 'dictionary-set-dictionary
(cons dictionary description) (cons dictionary description)
"Mouse-2 to select this dictionary") "Mouse-2 to select this dictionary")
@ -969,7 +969,7 @@ If PATTERN is omitted, it defaults to \"[ \\f\\t\\n\\r\\v]+\"."
(description (cadr list))) (description (cadr list)))
(if strategy (if strategy
(progn (progn
(link-insert-link description 'dictionary-reference-face (dictionary-link-insert-link description 'dictionary-reference-face
'dictionary-set-strategy strategy 'dictionary-set-strategy strategy
"Mouse-2 to select this matching algorithm") "Mouse-2 to select this matching algorithm")
(insert "\n"))))) (insert "\n")))))
@ -1071,7 +1071,7 @@ If PATTERN is omitted, it defaults to \"[ \\f\\t\\n\\r\\v]+\"."
(mapc (lambda (word) (mapc (lambda (word)
(setq word (dictionary-decode-charset word dictionary)) (setq word (dictionary-decode-charset word dictionary))
(insert " ") (insert " ")
(link-insert-link word (dictionary-link-insert-link word
'dictionary-reference-face 'dictionary-reference-face
'dictionary-new-search 'dictionary-new-search
(cons word dictionary) (cons word dictionary)
@ -1133,7 +1133,7 @@ It presents the word at point as default input and allows editing it."
(defun dictionary-next-link () (defun dictionary-next-link ()
"Place the cursor to the next link." "Place the cursor to the next link."
(interactive) (interactive)
(let ((pos (link-next-link))) (let ((pos (dictionary-link-next-link)))
(if pos (if pos
(goto-char pos) (goto-char pos)
(error "There is no next link")))) (error "There is no next link"))))
@ -1141,7 +1141,7 @@ It presents the word at point as default input and allows editing it."
(defun dictionary-prev-link () (defun dictionary-prev-link ()
"Place the cursor to the previous link." "Place the cursor to the previous link."
(interactive) (interactive)
(let ((pos (link-prev-link))) (let ((pos (dictionary-link-prev-link)))
(if pos (if pos
(goto-char pos) (goto-char pos)
(error "There is no previous link")))) (error "There is no previous link"))))