Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle multi-line strings sent to "open file" service #128

Merged
merged 1 commit into from Apr 26, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion lisp/term/ns-win.el
Original file line number Diff line number Diff line change
Expand Up @@ -264,14 +264,30 @@ The properties returned may include `top', `left', `height', and `width'."

(declare-function dnd-open-file "dnd" (uri action))

;; from http://ergoemacs.org/emacs/modernization_elisp_lib_problem.html
(defun trim-string (string)
"Remove white spaces in beginning and ending of STRING.
White space here is any of: space, tab, emacs newline (line feed, ASCII 10)."
(replace-regexp-in-string "\\`[ \t\n]*" "" (replace-regexp-in-string "[ \t\n]*\\'" "" string))
)

;; function to handle multi line strings that are passed to the "open-file" service
(defun open-file-service (filepaths)
"Opens multiple files at once when multiline string is selected."
(setq path_list (split-string filepaths "[\f\t\n\r\v]+"))
(while path_list
(if (not (equal "" (car path_list)))
(dnd-open-file (trim-string (car path_list)) nil))
(setq path_list (cdr path_list))))

(defun ns-spi-service-call ()
"Respond to a service request."
(interactive)
(cond ((string-equal ns-input-spi-name "open-selection")
(switch-to-buffer (generate-new-buffer "*untitled*"))
(insert ns-input-spi-arg))
((string-equal ns-input-spi-name "open-file")
(dnd-open-file ns-input-spi-arg nil))
(open-file-service ns-input-spi-arg))
((string-equal ns-input-spi-name "mail-selection")
(compose-mail)
(rfc822-goto-eoh)
Expand Down