* bug#69098: [PATCH] Add new command 'browse-url-here' @ 2024-02-13 10:09 Philip Kaludercic 2024-02-13 11:57 ` Felician Nemeth 0 siblings, 1 reply; 5+ messages in thread From: Philip Kaludercic @ 2024-02-13 10:09 UTC (permalink / raw) To: 69098 [-- Attachment #1: Type: text/plain, Size: 228 bytes --] The idea is to have a command that can be used to open a file or directory using something outside Emacs. I find this useful, but it might be that there are edge-cases that I am not considering that don't pop up on my system. [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: [PATCH] Add new command 'browse-url-here' --] [-- Type: text/x-patch, Size: 1779 bytes --] From 1f25f653ba35cb2c63a481522ffbf727bc2f5dd3 Mon Sep 17 00:00:00 2001 From: Philip Kaludercic <philipk@posteo.net> Date: Tue, 13 Feb 2024 11:08:09 +0100 Subject: [PATCH] Add new command 'browse-url-here' * lisp/net/browse-url.el (browse-url-here): Add it. * etc/NEWS: Document it. --- etc/NEWS | 4 ++++ lisp/net/browse-url.el | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/etc/NEWS b/etc/NEWS index e7e516d61a1..ea7cd1fc517 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -317,6 +317,10 @@ Previously, it was set to t but this broke remote file name detection. ** Multi-character key echo now ends with a suggestion to use Help. Customize 'echo-keystrokes-help' to nil to prevent that. +** New command 'browse-url-here'. +This command opens the current file or directory using an external tool, +as defined by 'browse-url-of-file'. + \f * Editing Changes in Emacs 30.1 diff --git a/lisp/net/browse-url.el b/lisp/net/browse-url.el index bc2a7db9a8b..abc1e9e5829 100644 --- a/lisp/net/browse-url.el +++ b/lisp/net/browse-url.el @@ -943,6 +943,19 @@ browse-url-at-point browse-url-new-window-flag)) (error "No URL found")))) +(defun browse-url-here (arg) + "Open current file or directory with external tools. +With prefix argument ARG, open the current `default-directory' instead +of the buffer of the current file." + (interactive "P") + (let ((browse-url-default-handlers '())) + (browse-url-of-file + (expand-file-name + (or (and arg ".") + (and (derived-mode-p 'dired-mode) + (dired-get-filename)) + buffer-file-name "."))))) + ;;;###autoload (defun browse-url-with-browser-kind (kind url &optional arg) "Browse URL with a browser of the given browser KIND. -- 2.43.0 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* bug#69098: [PATCH] Add new command 'browse-url-here' 2024-02-13 10:09 bug#69098: [PATCH] Add new command 'browse-url-here' Philip Kaludercic @ 2024-02-13 11:57 ` Felician Nemeth 2024-02-14 17:11 ` Philip Kaludercic 0 siblings, 1 reply; 5+ messages in thread From: Felician Nemeth @ 2024-02-13 11:57 UTC (permalink / raw) To: Philip Kaludercic; +Cc: 69098 Philip Kaludercic <philipk@posteo.net> writes: > The idea is to have a command that can be used to open a file or > directory using something outside Emacs. > > I find this useful, but it might be that there are edge-cases that I am > not considering that don't pop up on my system. Shouldn't it do something when the buffer is modified? > +(defun browse-url-here (arg) Since browse-url-of-buffer does something similar, the name could be more descriptive. Maybe browse-url-of-buffer-external? > + "Open current file or directory with external tools. > +With prefix argument ARG, open the current `default-directory' instead > +of the buffer of the current file." "the file of the current buffer." > + (interactive "P") > + (let ((browse-url-default-handlers '())) This is strange. There are other ways to use an external browser-kind. Maybe you could use browse-url-secondary-browser-function, which is "usually an external browser". > + (browse-url-of-file > + (expand-file-name > + (or (and arg ".") > + (and (derived-mode-p 'dired-mode) > + (dired-get-filename)) > + buffer-file-name "."))))) ^ permalink raw reply [flat|nested] 5+ messages in thread
* bug#69098: [PATCH] Add new command 'browse-url-here' 2024-02-13 11:57 ` Felician Nemeth @ 2024-02-14 17:11 ` Philip Kaludercic 2024-02-18 8:41 ` Felician Nemeth 0 siblings, 1 reply; 5+ messages in thread From: Philip Kaludercic @ 2024-02-14 17:11 UTC (permalink / raw) To: Felician Nemeth; +Cc: 69098 [-- Attachment #1: Type: text/plain, Size: 1406 bytes --] Felician Nemeth <felician.nemeth@gmail.com> writes: > Philip Kaludercic <philipk@posteo.net> writes: > >> The idea is to have a command that can be used to open a file or >> directory using something outside Emacs. >> >> I find this useful, but it might be that there are edge-cases that I am >> not considering that don't pop up on my system. > > Shouldn't it do something when the buffer is modified? A warning is generated by `browse-url-of-file'. >> +(defun browse-url-here (arg) > > Since browse-url-of-buffer does something similar, the name could be > more descriptive. Maybe browse-url-of-buffer-external? I like that name, used it. >> + "Open current file or directory with external tools. >> +With prefix argument ARG, open the current `default-directory' instead >> +of the buffer of the current file." > > "the file of the current buffer." Done, thanks. >> + (interactive "P") >> + (let ((browse-url-default-handlers '())) > > This is strange. There are other ways to use an external browser-kind. > Maybe you could use browse-url-secondary-browser-function, which is > "usually an external browser". The thing is if `browse-url-default-handlers' includes (browse-url--non-html-file-url-p . browse-url-emacs) then this catches all the requests and the file is always opened in Emacs. In this patch I try to only filter out these entries that would open the file in Emacs: [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: 0001-Add-new-command-browse-url-of-buffer-external.patch --] [-- Type: text/x-patch, Size: 7937 bytes --] From 58cc4a8a3fc8d5ae87c1a443d02715d65c776675 Mon Sep 17 00:00:00 2001 From: Philip Kaludercic <philipk@posteo.net> Date: Tue, 13 Feb 2024 11:08:09 +0100 Subject: [PATCH] Add new command 'browse-url-of-buffer-external' * lisp/net/browse-url.el (browse-url-of-buffer-external): Add it. * etc/NEWS: Document it. --- etc/NEWS | 4 + etc/package-autosuggest.eld | 11 +++ lisp/net/browse-url.el | 20 +++++ lisp/textmodes/markdown-ts-mode.el | 135 +++++++++++++++++++++++++++++ 4 files changed, 170 insertions(+) create mode 100644 etc/package-autosuggest.eld create mode 100644 lisp/textmodes/markdown-ts-mode.el diff --git a/etc/NEWS b/etc/NEWS index a2b5e0d1a9a..b7c9fc9aa81 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -324,6 +324,10 @@ Previously, it was set to t but this broke remote file name detection. ** Multi-character key echo now ends with a suggestion to use Help. Customize 'echo-keystrokes-help' to nil to prevent that. +** New command 'browse-url-of-buffer-external'. +This command opens the current file or directory using an external tool, +as defined by 'browse-url-secondary-browser-function'. + \f * Editing Changes in Emacs 30.1 diff --git a/etc/package-autosuggest.eld b/etc/package-autosuggest.eld new file mode 100644 index 00000000000..87c7e382026 --- /dev/null +++ b/etc/package-autosuggest.eld @@ -0,0 +1,11 @@ +((sml-mode auto-mode-alist "\\.sml\\'") + (lua-mode auto-mode-alist "\\.lua\\'" ) + (ada-mode auto-mode-alist "\\.ada\\'") + ;; ... + ;; + ;; this is just for testing, in practice I think this data should + ;; be generated and bundled with Emacs, and would ideally be + ;; loaded in at compile-time. When the "archive-contents" file + ;; format is updated, we can include more information in there + ;; that would be added to this database. + ) diff --git a/lisp/net/browse-url.el b/lisp/net/browse-url.el index bc2a7db9a8b..e017d679d84 100644 --- a/lisp/net/browse-url.el +++ b/lisp/net/browse-url.el @@ -943,6 +943,26 @@ browse-url-at-point browse-url-new-window-flag)) (error "No URL found")))) +(defun browse-url-of-buffer-external (arg) + "Open current file or directory with external tools. +With prefix argument ARG, open the current `default-directory' instead +of the file of the current buffer." + (interactive "P") + (let ((browse-url-browser-function + browse-url-secondary-browser-function) + (browse-url-default-handlers + (seq-filter + (lambda (ent) (eq (cdr ent) 'browse-url-emacs)) + browse-url-default-handlers))) + (browse-url-of-file + (expand-file-name + (cond + (arg ".") + ((derived-mode-p 'dired-mode) + (dired-get-filename)) + (buffer-file-name) + ((user-error "No associated file found"))))))) + ;;;###autoload (defun browse-url-with-browser-kind (kind url &optional arg) "Browse URL with a browser of the given browser KIND. diff --git a/lisp/textmodes/markdown-ts-mode.el b/lisp/textmodes/markdown-ts-mode.el new file mode 100644 index 00000000000..60321d789eb --- /dev/null +++ b/lisp/textmodes/markdown-ts-mode.el @@ -0,0 +1,135 @@ +;;; markdown-ts-mode.el --- Markdown editing mode -*- lexical-binding: t; -*- + +;; Copyright (C) 2023 Free Software Foundation, Inc. + +;; Author: Philip Kaludercic <philipk@posteo.net> +;; Keywords: languages + +;; This file is part of GNU Emacs. + +;; GNU Emacs 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. + +;; GNU Emacs 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 GNU Emacs. If not, see <https://www.gnu.org/licenses/>. + +;;; Commentary: + +;; Major mode for Markdown. The syntax highlighting has been +;; implemented using Tree Sitter. + +;;; Code: + +(eval-when-compile (require 'pcase)) +(require 'treesit) + +(defgroup markdown-ts-mode '() + "Markdown support." + :prefix "markdown-ts-" + :group 'text) + +(defcustom markdown-ts-mode-executable + (seq-find #'executable-find '("cmark" "pandoc" "markdown")) + "Name of the executable used to render Markdown. +It should read the Markdown text via stdin, and render HTML via +the standard output." + :type 'string) + +(defconst markdown-ts-mode-font-lock-rules + (treesit-font-lock-rules + :language 'markdown + :feature 'bracket + '((["[" "]" "{" "}"]) @font-lock-bracket-face) + ;; TODO + ) + "Markdown settings suitable for `treesit-font-lock-settings'.") + +(defun markdown-ts-mode-insert-markup (left right) + "Generate a new command for inserting markup. +Insert LEFT and RIGHT into the current buffer. +Both arguments are strings that are inserted LEFT and RIGHT of +the active region, or if not present the current point. This +function is meant to be invoked by other commands that specialise +on a specific kind of formatting." + (lambda () + (interactive) + (if (use-region-p) + (save-mark-and-excursion + (goto-char (region-end)) + (insert right) + (goto-char (region-beginning)) + (insert left)) + (insert left) + (save-excursion (insert right))))) + +(defalias 'markdown-ts-mode-insert-bold + (markdown-ts-mode-insert-markup "**" "**") + "Insert bold markup.") + +(defalias 'markdown-ts-mode-insert-italics + (markdown-ts-mode-insert-markup "_" "_") + "Insert italic markup.") + +;; (defalias 'markdown-ts-mode-insert-link (uri) +;; (markdown-ts-mode-insert-markup +;; "[" (format "](%s)" uri)) +;; "Insert a link to a URI." +;; (interactive "MURI: ") +;; ) + +(defun markdown-ts-mode-render () + "Render the current buffer using EWW." + (interactive) + (unless markdown-ts-mode-executable + (user-error "No markdown available")) + (let ((bounds (bounds-of-thing-at-point (if (use-region-p) + 'region + 'buffer))) + (file (make-temp-file "markdown" nil ".html"))) + (call-process-region (car bounds) (cdr bounds) + markdown-ts-mode-executable + nil (list :file file)) + (eww-open-file file))) + +(defvar-keymap markdown-ts-mode-map + "C-c C-f C-b" #'markdown-ts-mode-insert-bold + "C-c C-f C-i" #'markdown-ts-mode-insert-italics + ;; "C-c C-l" #'markdown-ts-mode-insert-link + "C-c C-c" #'markdown-ts-mode-render) + +;;;###autoload +(define-derived-mode markdown-ts-mode text-mode "MD" + "Major mode for editing Markdown files. +This implementation makes use of Tree Sitter (see the Info +Node `(elisp) Tree-sitter Major Modes'), and relies on external +support for rendering. Using `treesit-install-language-grammar' +you can install a grammar." + (unless (treesit-ready-p 'markdown) + (user-error "Tree Sitter support is not available")) + (treesit-parser-create 'markdown) + (setq-local treesit-font-lock-settings + markdown-ts-mode-font-lock-rules + treesit-font-lock-feature-list + '((constant escape-sequence number property) + (bracket delimiter error misc-punctuation) + (string type) + (comment)) + comment-start "# ") + (treesit-major-mode-setup)) + +(when (treesit-ready-p 'markdown) + (add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-ts-mode))) + +(add-to-list + 'treesit-language-source-alist + '(markdown "https://github.com/ikatyang/tree-sitter-markdown" "v0.7.1")) + +;;; markdown-ts-mode.el ends here +(provide 'markdown-ts-mode) -- 2.43.0 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* bug#69098: [PATCH] Add new command 'browse-url-here' 2024-02-14 17:11 ` Philip Kaludercic @ 2024-02-18 8:41 ` Felician Nemeth 2024-02-18 12:36 ` Philip Kaludercic 0 siblings, 1 reply; 5+ messages in thread From: Felician Nemeth @ 2024-02-18 8:41 UTC (permalink / raw) To: Philip Kaludercic; +Cc: 69098 [-- Attachment #1: Type: text/plain, Size: 772 bytes --] >> Philip Kaludercic <philipk@posteo.net> writes: >> >>> The idea is to have a command that can be used to open a file or >>> directory using something outside Emacs. >>> >>> I find this useful, but it might be that there are edge-cases that I am >>> not considering that don't pop up on my system. Now I think the attached patch is more inline with the philosophy of browse-url than the previous patches of this thread. However, this patch might not be necessary. You can open a file with C-x C-j W or in the secondary browser with C-x C-j C-u W. This seems cumbersome, but C-x C-j (dired-jump) quickly becomes second nature. And to open the directory of file: C-x C-j C-x C-j C-u W, which once again seems frightening, but can be entered quickly without thinking. [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: 0001-Allow-browse-url-commands-to-invoke-secondary-browse.patch --] [-- Type: text/x-diff, Size: 3055 bytes --] From a5227603c87ae899a6ccf7e581b80a0f6b816946 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felici=C3=A1n=20N=C3=A9meth?= <felician.nemeth@gmail.com> Date: Sun, 18 Feb 2024 09:22:30 +0100 Subject: [PATCH] Allow browse-url commands to invoke secondary browser * lisp/net/browse-url.el (browse-url-of-file) (browse-url-of-buffer): Use 'browse-url-secondary-browser-function' if the new argument 'secondary' is non-nil or when invoked with a prefix arg. --- lisp/net/browse-url.el | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/lisp/net/browse-url.el b/lisp/net/browse-url.el index 74740af3bd6..4c4c79a80da 100644 --- a/lisp/net/browse-url.el +++ b/lisp/net/browse-url.el @@ -728,13 +728,16 @@ browse-url-maybe-new-window ;; Browse current buffer ;;;###autoload -(defun browse-url-of-file (&optional file) +(defun browse-url-of-file (&optional file secondary) "Use a web browser to display FILE. Display the current buffer's file if FILE is nil or if called interactively. Turn the filename into a URL with function `browse-url-file-url'. Pass the URL to a browser using the -`browse-url' function then run `browse-url-of-file-hook'." - (interactive) +`browse-url' function then run `browse-url-of-file-hook'. + +With a prefix argument, or when SECONDARY is non-nil, use +`browse-url-secondary-browser-function' instead." + (interactive (list nil current-prefix-arg)) (or file (setq file (buffer-file-name)) (error "Current buffer has no file")) @@ -748,7 +751,10 @@ browse-url-of-file (not browse-url-temp-file-name)) (setq browse-url-temp-file-name (file-local-copy file) file browse-url-temp-file-name)) - (browse-url (browse-url-file-url file)) + (let ((url (browse-url-file-url file))) + (if secondary + (funcall browse-url-secondary-browser-function url) + (browse-url url))) (run-hooks 'browse-url-of-file-hook)) (defun browse-url--file-name-coding-system () @@ -789,14 +795,17 @@ browse-url-file-url file) ;;;###autoload -(defun browse-url-of-buffer (&optional buffer) +(defun browse-url-of-buffer (&optional buffer secondary) "Use a web browser to display BUFFER. See `browse-url' for details. Display the current buffer if BUFFER is nil. Display only the currently visible part of BUFFER (from a temporary file) if buffer is -narrowed." - (interactive) +narrowed. + +With a prefix argument, or when SECONDARY is non-nil, use +`browse-url-secondary-browser-function' instead." + (interactive (list nil current-prefix-arg)) (save-excursion (and buffer (set-buffer buffer)) (let ((file-name @@ -816,7 +825,7 @@ browse-url-of-buffer nil ".html")))) (setq file-name browse-url-temp-file-name) (write-region (point-min) (point-max) file-name nil 'no-message)) - (browse-url-of-file file-name)))) + (browse-url-of-file file-name secondary)))) (defun browse-url-delete-temp-file (&optional temp-file-name) "Delete `browse-url-temp-file-name' from the file system. -- 2.39.2 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* bug#69098: [PATCH] Add new command 'browse-url-here' 2024-02-18 8:41 ` Felician Nemeth @ 2024-02-18 12:36 ` Philip Kaludercic 0 siblings, 0 replies; 5+ messages in thread From: Philip Kaludercic @ 2024-02-18 12:36 UTC (permalink / raw) To: Felician Nemeth; +Cc: 69098 Felician Nemeth <felician.nemeth@gmail.com> writes: >>> Philip Kaludercic <philipk@posteo.net> writes: >>> >>>> The idea is to have a command that can be used to open a file or >>>> directory using something outside Emacs. >>>> >>>> I find this useful, but it might be that there are edge-cases that I am >>>> not considering that don't pop up on my system. > > Now I think the attached patch is more inline with the philosophy of > browse-url than the previous patches of this thread. > > However, this patch might not be necessary. You can open a file with > C-x C-j W or in the secondary browser with C-x C-j C-u W. This seems > cumbersome, but C-x C-j (dired-jump) quickly becomes second nature. And > to open the directory of file: C-x C-j C-x C-j C-u W, which once again > seems frightening, but can be entered quickly without thinking. > > From a5227603c87ae899a6ccf7e581b80a0f6b816946 Mon Sep 17 00:00:00 2001 > From: =?UTF-8?q?Felici=C3=A1n=20N=C3=A9meth?= <felician.nemeth@gmail.com> > Date: Sun, 18 Feb 2024 09:22:30 +0100 > Subject: [PATCH] Allow browse-url commands to invoke secondary browser > > * lisp/net/browse-url.el (browse-url-of-file) > (browse-url-of-buffer): Use 'browse-url-secondary-browser-function' > if the new argument 'secondary' is non-nil or when invoked with a > prefix arg. > --- > lisp/net/browse-url.el | 25 +++++++++++++++++-------- > 1 file changed, 17 insertions(+), 8 deletions(-) > > diff --git a/lisp/net/browse-url.el b/lisp/net/browse-url.el > index 74740af3bd6..4c4c79a80da 100644 > --- a/lisp/net/browse-url.el > +++ b/lisp/net/browse-url.el > @@ -728,13 +728,16 @@ browse-url-maybe-new-window > ;; Browse current buffer > > ;;;###autoload > -(defun browse-url-of-file (&optional file) > +(defun browse-url-of-file (&optional file secondary) > "Use a web browser to display FILE. > Display the current buffer's file if FILE is nil or if called > interactively. Turn the filename into a URL with function > `browse-url-file-url'. Pass the URL to a browser using the > -`browse-url' function then run `browse-url-of-file-hook'." > - (interactive) > +`browse-url' function then run `browse-url-of-file-hook'. > + > +With a prefix argument, or when SECONDARY is non-nil, use > +`browse-url-secondary-browser-function' instead." > + (interactive (list nil current-prefix-arg)) This would lack the convince feature of being able to also quickly open the current directory, which is what I used the prefix argument for. > (or file > (setq file (buffer-file-name)) > (error "Current buffer has no file")) > @@ -748,7 +751,10 @@ browse-url-of-file > (not browse-url-temp-file-name)) > (setq browse-url-temp-file-name (file-local-copy file) > file browse-url-temp-file-name)) > - (browse-url (browse-url-file-url file)) > + (let ((url (browse-url-file-url file))) > + (if secondary > + (funcall browse-url-secondary-browser-function url) > + (browse-url url))) > (run-hooks 'browse-url-of-file-hook)) > > (defun browse-url--file-name-coding-system () > @@ -789,14 +795,17 @@ browse-url-file-url > file) > > ;;;###autoload > -(defun browse-url-of-buffer (&optional buffer) > +(defun browse-url-of-buffer (&optional buffer secondary) > "Use a web browser to display BUFFER. > See `browse-url' for details. > > Display the current buffer if BUFFER is nil. Display only the > currently visible part of BUFFER (from a temporary file) if buffer is > -narrowed." > - (interactive) > +narrowed. > + > +With a prefix argument, or when SECONDARY is non-nil, use > +`browse-url-secondary-browser-function' instead." > + (interactive (list nil current-prefix-arg)) > (save-excursion > (and buffer (set-buffer buffer)) > (let ((file-name > @@ -816,7 +825,7 @@ browse-url-of-buffer > nil ".html")))) > (setq file-name browse-url-temp-file-name) > (write-region (point-min) (point-max) file-name nil 'no-message)) > - (browse-url-of-file file-name)))) > + (browse-url-of-file file-name secondary)))) > > (defun browse-url-delete-temp-file (&optional temp-file-name) > "Delete `browse-url-temp-file-name' from the file system. -- Philip Kaludercic ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-02-18 12:36 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2024-02-13 10:09 bug#69098: [PATCH] Add new command 'browse-url-here' Philip Kaludercic 2024-02-13 11:57 ` Felician Nemeth 2024-02-14 17:11 ` Philip Kaludercic 2024-02-18 8:41 ` Felician Nemeth 2024-02-18 12:36 ` Philip Kaludercic
Code repositories for project(s) associated with this external index https://git.savannah.gnu.org/cgit/emacs.git https://git.savannah.gnu.org/cgit/emacs/org-mode.git This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.