Add new ein-completer.el for completion functions

This commit is contained in:
Takafumi Arakaki 2012-05-15 21:46:17 +02:00
parent e7880d4b65
commit efaaeb98c1
3 changed files with 47 additions and 14 deletions

View file

@ -360,17 +360,6 @@ A specific node can be specified using optional ARGS."
(ewoc-invalidate (oref cell :ewoc)
(ein:cell-element-get cell :prompt))))
(defun ein:cell-finish-completing (cell matched-text matches)
(let* ((end (point))
(beg (save-excursion
(re-search-backward (concat matched-text "\\="))))
(word (if (and beg matches)
(completing-read "Complete: " matches
nil nil matched-text))))
(when word
(delete-region beg end)
(insert word))))
(defun ein:cell-finish-tooltip (cell content)
;; FIXME: implement!
(ein:log 'info "`ein:cell-finish-tooltip' is not implemented!"))

44
ein-completer.el Normal file
View file

@ -0,0 +1,44 @@
;;; ein-completer.el --- Completion module
;; Copyright (C) 2012- Takafumi Arakaki
;; Author: Takafumi Arakaki
;; This file is NOT part of GNU Emacs.
;; ein-completer.el 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.
;; ein-completer.el 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 ein-completer.el. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;;
;;; Code:
(defun ein:completer-beginning (matched-text)
(save-excursion
(re-search-backward (concat matched-text "\\="))))
(defun ein:completer-finish-completing (matched-text matches)
(let* ((end (point))
(beg (ein:completer-beginning matched-text))
(word (if (and beg matches)
(completing-read "Complete: " matches
nil nil matched-text))))
(when word
(delete-region beg end)
(insert word))))
(provide 'ein-completer)
;;; ein-completer.el ends here

View file

@ -34,6 +34,7 @@
(require 'ein-node)
(require 'ein-kernel)
(require 'ein-cell)
(require 'ein-completer)
(require 'ein-pager)
(require 'ein-events)
(require 'ein-kill-ring)
@ -381,9 +382,8 @@ when the prefix argument is given."
(ein:cell-running-set cell nil)
(setf (ein:$notebook-dirty notebook) t))
((equal msg_type "complete_reply")
(ein:cell-finish-completing cell
(plist-get content :matched_text)
(plist-get content :matches)))
(ein:completer-finish-completing (plist-get content :matched_text)
(plist-get content :matches)))
((equal msg_type "object_info_reply")
(when (plist-get content :found)
(ein:cell-finish-tooltip cell content)))