al-dictem.el 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. ;;; al-dictem.el --- Additional functionality for dictem
  2. ;; Copyright © 2013-2016 Alex Kost
  3. ;; This program is free software; you can redistribute it and/or modify
  4. ;; it under the terms of the GNU General Public License as published by
  5. ;; the Free Software Foundation, either version 3 of the License, or
  6. ;; (at your option) any later version.
  7. ;; This program is distributed in the hope that it will be useful,
  8. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. ;; GNU General Public License for more details.
  11. ;; You should have received a copy of the GNU General Public License
  12. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ;;; Code:
  14. (require 'dictem)
  15. (require 'al-read)
  16. (defun al/dictem ()
  17. "Same as `dictem' but do not use other window for a dictem buffer."
  18. (let ((buffer (generate-new-buffer dictem-buffer-name))
  19. (window-configuration (current-window-configuration))
  20. (selected-window (frame-selected-window)))
  21. (switch-to-buffer buffer) ; not `switch-to-buffer-other-window'
  22. (dictem-mode)
  23. (make-local-variable 'dictem-window-configuration)
  24. (make-local-variable 'dictem-selected-window)
  25. (make-local-variable 'dictem-content-history)
  26. (setq dictem-window-configuration window-configuration)
  27. (setq dictem-selected-window selected-window)))
  28. (defun al/dictem-define-on-press ()
  29. "Same as `dictem-define-on-press' but with \"*\" for dicts."
  30. (interactive)
  31. (let* ((properties (text-properties-at (point)))
  32. (data (plist-get properties 'link-data))
  33. (fun (plist-get properties 'link-function))
  34. (dictem-server (plist-get properties 'dictem-server))
  35. (dictem-port (plist-get properties 'dictem-port))
  36. (word (assq 'word data))
  37. (dbname (assq 'dbname data)))
  38. (if (or word dbname)
  39. (dictem-run fun "*"
  40. ;; "*" instead of:
  41. ;; (if dbname (cdr dbname) dictem-last-database)
  42. (if word (cdr word) nil)
  43. nil))))
  44. (defun al/dictem-read-query (&optional default-query)
  45. "Similar to `dictem-read-query', but uses `al/read-string'."
  46. (al/read-string "Query word" nil 'dictem-query-history default-query))
  47. (defvar al/dictem-dicts '(nil "mueller7")
  48. "List of dictionaries to search by `al/dictem-run-word'.
  49. dictem ignores the first dictionary, so the first element of the
  50. list should be nil.")
  51. ;;;###autoload
  52. (defun al/dictem-run-word (&optional word)
  53. "Ask about word and show definitions in new buffer."
  54. (interactive)
  55. (let ((dictem-server nil))
  56. (dictem-run 'dictem-base-define
  57. al/dictem-dicts
  58. (or word (al/dictem-read-query (thing-at-point 'word)))
  59. "exact")))
  60. ;;;###autoload
  61. (defun al/dictem-run-dict-search ()
  62. "Search in \"dict.org\". Ask about search strategy and query."
  63. (interactive)
  64. (let ((dictem-server "dict.org")
  65. (query (al/dictem-read-query (thing-at-point 'word)))
  66. (strat (dictem-select-strategy (dictem-get-default-strategy))))
  67. (dictem-run 'dictem-base-search "*" query strat)))
  68. ;;;###autoload
  69. (defun al/dictem-run-show-all-info ()
  70. "Show information about all local databases"
  71. (interactive)
  72. (let ((dictem-server "localhost"))
  73. (dictem-run
  74. (lambda (a b c)
  75. (dictem-base-show-strategies nil nil nil)
  76. (dictem-base-show-databases nil nil nil)
  77. (dictem-base-show-server nil nil nil)))))
  78. (provide 'al-dictem)
  79. ;;; al-dictem.el ends here