SLY: Escape wildcards and double quotes when completing / inserting pathnames.
parent
934c3a5a75
commit
572dd078fc
|
@ -52,6 +52,9 @@ See also `process-lines'."
|
||||||
(ediff-get-region-contents ediff-current-difference 'A ediff-control-buffer)
|
(ediff-get-region-contents ediff-current-difference 'A ediff-control-buffer)
|
||||||
(ediff-get-region-contents ediff-current-difference 'B ediff-control-buffer))))
|
(ediff-get-region-contents ediff-current-difference 'B ediff-control-buffer))))
|
||||||
|
|
||||||
|
(defun ambrevar/escape-cl-wildcards (s)
|
||||||
|
(replace-regexp-in-string "\\([]*?[]\\)" "\\\\\\1" s))
|
||||||
|
|
||||||
(defun ambrevar/escape-region (&optional regex to-string)
|
(defun ambrevar/escape-region (&optional regex to-string)
|
||||||
"Escape double-quotes and backslashes.
|
"Escape double-quotes and backslashes.
|
||||||
This is useful for writing Elisp strings containing those
|
This is useful for writing Elisp strings containing those
|
||||||
|
|
|
@ -200,6 +200,11 @@ Good substitute for `sly-mrepl-indent-and-complete-symbol'."
|
||||||
"Prefix for `ambrevar/complete-cl-file'."
|
"Prefix for `ambrevar/complete-cl-file'."
|
||||||
:type 'string)
|
:type 'string)
|
||||||
|
|
||||||
|
;; #f is for FOF.
|
||||||
|
(defcustom ambrevar/complete-cl-reader-macros '("#p" "#f")
|
||||||
|
"List of supported reader macros for `ambrevar/complete-cl-file'."
|
||||||
|
:type 'list)
|
||||||
|
|
||||||
(defun ambrevar/complete-cl-file (action &rest _)
|
(defun ambrevar/complete-cl-file (action &rest _)
|
||||||
(interactive (list 'interactive))
|
(interactive (list 'interactive))
|
||||||
(cl-flet ((look-back
|
(cl-flet ((look-back
|
||||||
|
@ -210,19 +215,25 @@ Good substitute for `sly-mrepl-indent-and-complete-symbol'."
|
||||||
(looking-back expr
|
(looking-back expr
|
||||||
(when use-limit
|
(when use-limit
|
||||||
(- (point) (length expr))))))
|
(- (point) (length expr))))))
|
||||||
;; #f is for FOF.
|
ambrevar/complete-cl-reader-macros))
|
||||||
'("#p" "#f"))))
|
(cl-files
|
||||||
|
()
|
||||||
|
(mapcar (lambda (s) (prin1-to-string (make-symbol (ambrevar/escape-cl-wildcards s))))
|
||||||
|
(company-files 'candidates ambrevar/complete-cl-file-prefix))))
|
||||||
(cl-case action
|
(cl-case action
|
||||||
(interactive (company-begin-backend #'my/complete-cl-file))
|
(interactive (company-begin-backend #'my/complete-cl-file))
|
||||||
(candidates
|
(candidates
|
||||||
(cond ((and (save-match-data (look-back :use-limit t)))
|
(cond ((and (save-match-data (look-back :use-limit t)))
|
||||||
|
;; TODO: Is it possible to move point after quotes after completing?
|
||||||
(if (looking-at-p "\"")
|
(if (looking-at-p "\"")
|
||||||
(company-files 'candidates ambrevar/complete-cl-file-prefix)
|
(forward-char)
|
||||||
(mapcar (lambda (s)
|
(insert "\"")
|
||||||
(concat "\"" s "\""))
|
(save-excursion (insert "\"")))
|
||||||
(company-files 'candidates ambrevar/complete-cl-file-prefix))))
|
(cl-files))
|
||||||
((save-match-data (look-back :suffix "\"" :use-limit t))
|
((save-match-data (look-back :suffix "\"" :use-limit t))
|
||||||
(company-files 'candidates ambrevar/complete-cl-file-prefix))))
|
(mapcar (lambda (s) (prin1-to-string (make-symbol (ambrevar/escape-cl-wildcards s))))
|
||||||
|
(company-files 'candidates ambrevar/complete-cl-file-prefix))
|
||||||
|
(cl-files))))
|
||||||
(prefix (and (save-match-data (look-back :suffix "\"?")) ""))
|
(prefix (and (save-match-data (look-back :suffix "\"?")) ""))
|
||||||
(t (company-files action)))))
|
(t (company-files action)))))
|
||||||
|
|
||||||
|
|
|
@ -27,18 +27,7 @@ of the full, abbreviated or relative paths to insert."
|
||||||
guess))))
|
guess))))
|
||||||
(escape-fn (cond
|
(escape-fn (cond
|
||||||
((derived-mode-p 'sly-mrepl-mode)
|
((derived-mode-p 'sly-mrepl-mode)
|
||||||
;; TODO: Inserting the path as is does not work with
|
(lambda (s) (prin1-to-string (ambrevar/escape-cl-wildcards s))))
|
||||||
;; #p if the file has a wildcard, so we must escape it.
|
|
||||||
;; Or output uiop:ensure-pathname?
|
|
||||||
;;
|
|
||||||
;; In sbcl-ambrevar, we have FOF and we can use #f instead.
|
|
||||||
;;
|
|
||||||
;; (lambda (s)
|
|
||||||
;; (if (string-match-p (regexp-opt '("[" "]" "*") )
|
|
||||||
;; s)
|
|
||||||
;; (concat "(uiop:ensure-pathname \"" s "\")")
|
|
||||||
;; (concat "#p\"" s "\"")))
|
|
||||||
#'prin1-to-string)
|
|
||||||
((memq major-mode
|
((memq major-mode
|
||||||
helm-modes-using-escaped-strings)
|
helm-modes-using-escaped-strings)
|
||||||
#'shell-quote-argument)
|
#'shell-quote-argument)
|
||||||
|
|
Loading…
Reference in New Issue