Add my ediprolog misc function
This commit is contained in:
32
.config.d/99-my-ediprolog.el
Normal file
32
.config.d/99-my-ediprolog.el
Normal file
@@ -0,0 +1,32 @@
|
||||
;;; 99-my-ediprolog.el --- ediprolog extras -*- no-byte-compile: t; lexical-binding: t; -*-
|
||||
|
||||
(defun my/ediprolog-run-in-own-buffer ()
|
||||
"Copy this query to another buffer and run it there"
|
||||
(interactive)
|
||||
;; This is the same logic ediprolog uses to check if the point is on query.
|
||||
(when (and (not (and transient-mark-mode mark-active))
|
||||
(save-excursion
|
||||
(beginning-of-line)
|
||||
(looking-at "\\([\t ]*%*[\t ]*[:?]- *\\)")))
|
||||
(let* ((from (goto-char (match-end 0)))
|
||||
(to (if (re-search-forward "\\.[\t ]*\\(?:%.*\\)?$" nil t)
|
||||
;; omit trailing whitespace
|
||||
(+ (point) (skip-chars-backward "\t "))
|
||||
(error "Missing `.' at the end of this query")))
|
||||
(query (buffer-substring-no-properties from to))
|
||||
(buffer (get-buffer-create "*Prolog Query*")))
|
||||
|
||||
(pop-to-buffer buffer)
|
||||
|
||||
(unless (eq major-mode "prolog-mode")
|
||||
(prolog-mode))
|
||||
(goto-char (point-max))
|
||||
(unless (eq (line-number-at-pos) 1)
|
||||
(insert "\n\n"))
|
||||
(insert "/*\n ?- ")
|
||||
(save-excursion
|
||||
(insert query "\n*/"))
|
||||
|
||||
(ediprolog-dwim))))
|
||||
|
||||
;; 99-my-ediprolog.el ends here
|
||||
Reference in New Issue
Block a user