andorsk / d2-mode

emacs major mode for d2 graphs
GNU General Public License v3.0
63 stars 7 forks source link

use `xdg-open` on Linux and `open` on macOS instead of browse-url #31

Open suliveevil opened 1 year ago

suliveevil commented 1 year ago
Debugger entered--Lisp error: (wrong-type-argument commandp d2-open-browser)
  call-interactively(d2-open-browser nil nil)
  command-execute(d2-open-browser)

I know how to fix it but didn't learn enough emacs-lisp knowledge to achieve it. 🤣

suliveevil commented 1 year ago

Find a function to open file in default app

;; https://emacs-china.org/t/pdf/14954/5
(defun my/open-with (arg)
  "使用外部程序打开浏览的文件或者当前光标下的链接.
处于 dired mode 时, 打开当前光标下的文件;
若当前光标下存在链接,使用外部程序打开链接;
使用 prefix ARG 时指定使用的外部程序."
  (interactive "P")
  (let ((current-file-name
         (cond ((eq major-mode 'dired-mode) (dired-get-file-for-visit))
               ((help-at-pt-string)
                (pcase (cdr (split-string (help-at-pt-string) ":" t " "))
                  ((or `(,path) `(,(pred (string= "file")) ,path) `(,_ ,path ,_))
                   (expand-file-name path))
                  (`(,proto ,path) (concat proto ":" path))))
               (t (or (thing-at-point 'url) buffer-file-name))))
        (program (if arg
                     (read-shell-command "Open current file with: ")
                   "open")))
    (call-process program nil 0 nil current-file-name)))
andorsk commented 1 year ago

Thanks @suliveevil . I can't address this now but will put this on the docket to address as soon as possible.

arstum commented 1 year ago

The same as mine, it still exists.