* Bookmark a PDF, open in external program
@ 2015-01-31 16:37 Tory S. Anderson
2015-01-31 18:31 ` Drew Adams
0 siblings, 1 reply; 5+ messages in thread
From: Tory S. Anderson @ 2015-01-31 16:37 UTC (permalink / raw)
To: emacs list
I use the Bookmarks+ module (perhaps not relevant). I also frequently read PDFs. But when I bookmark a PDF, jumping to it causes it to open within emacs, rather than with my system default viewer. There are many people asking similar questions online but the answers don't seem to fit; I can't use the dired solution of `!` to execute a shell command in this case. Any tips?
^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: Bookmark a PDF, open in external program
2015-01-31 16:37 Bookmark a PDF, open in external program Tory S. Anderson
@ 2015-01-31 18:31 ` Drew Adams
2015-01-31 18:49 ` Tory S. Anderson
2015-02-10 18:50 ` Tory S. Anderson
0 siblings, 2 replies; 5+ messages in thread
From: Drew Adams @ 2015-01-31 18:31 UTC (permalink / raw)
To: torys.anderson, emacs list
> I use the Bookmarks+ module (perhaps not relevant). I also frequently read
> PDFs. But when I bookmark a PDF, jumping to it causes it to open within
> emacs, rather than with my system default viewer. There are many people
> asking similar questions online but the answers don't seem to fit; I can't
> use the dired solution of `!` to execute a shell command in this case. Any
> tips?
Since you use Bookmark+ the answer is yes, you can easily open
a bookmark that targets a PDF file using any application you like,
and you have several possibilities:
You can use option `bmkp-default-handlers-for-file-types' to
control which operation (bookmark handler) to use by default,
for which file types (e.g. PDF).
`M-x customize-option bmkp-default-handlers-for-file-types'
This is a set of associations (an alist), with each key being
a regexp matching file names, and with each associated value
being a Lisp sexp that evaluates to either a shell command
(a string) or an Emacs function (a symbol or lambda form).
You can think of `bmkp-default-handlers-for-file-types' as
somewhat analogous to `auto-mode-alist'. But it maps file-name
patterns to file actions instead of mapping them to buffer
modes. And it has an effect only when you use certain commands.
The default value of `bmkp-default-handlers-for-file-types'
is taken from the value of `dired-guess-shell-alist-user', so
you can, if you prefer, just customize that option. (That
option comes from standard library `dired-x.el'.)
If `bmkp-default-handlers-for-file-types' specifies no
matching association for a given file, and if option
`bmkp-guess-default-handler-for-file-flag' is non-nil,
then Bookmark+ guesses a shell command to use. It uses
`dired-guess-shell-alist-default' (first) and your mailcap
entries (second) to guess.
A bookmark that was created for a file without visiting it
(e.g., using `C-x p c f' or `C-x p c a') has its `file-handler'
property set automatically to the handler specified for its
type by `bmkp-default-handlers-for-file-types'.
If you are on MS Windows, then, in _addition_ to what is
said above:
* In the `*Bookmark List*' display you can use any of these to
open bookmarks using associated Windows `Open' applications:
`M-RET' - `bmkp-bmenu-w32-open': this bookmark (on this line)
`M-mouse-2' - `bmkp-bmenu-w32-open-with-mouse': clicked bookmark
`M-o' - `bmkp-bmenu-w32-jump-to-marked': this bookmark &
marked bookmarks
You can still associate particular bookmarks or file types
with particular shell commands or other programs, via option
`bmkp-default-handlers-for-file-types'.
But you can also take advantage of the file associations
that are defined outside Emacs, for Windows. You can thus
have two different associations for the same file type and
use either of them whenever you want.
* If you associate action `w32-browser' with a file type in
`bmkp-default-handlers-for-file-types' then you can use
command `bmkp-w32-browser-jump' (not bound to a key by
default) anytime to open a file of that type using the
Windows `Open' action.
* You can use command `bmkp-jump-to-type' (`C-x j :') and
input `w32-browser' as the bookmark type, to limit completion
candidates to bookmarks that are associated with `w32-browser'.
This is all covered in the Bookmark+ doc:
* All of the doc: http://www.emacswiki.org/emacs/BookmarkPlus
* `bmkp-default-handlers-for-file-types':
http://www.emacswiki.org/emacs/BookmarkPlus#BookmarkingFilesYouCannotVisitWithEmacs
* Using MS Windows file associations:
http://www.emacswiki.org/emacs/BookmarkPlus#WindowsFileAssociations
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Bookmark a PDF, open in external program
2015-01-31 18:31 ` Drew Adams
@ 2015-01-31 18:49 ` Tory S. Anderson
2015-02-10 18:50 ` Tory S. Anderson
1 sibling, 0 replies; 5+ messages in thread
From: Tory S. Anderson @ 2015-01-31 18:49 UTC (permalink / raw)
To: Drew Adams; +Cc: emacs list
Excellent answer. Thanks, Drew.
Drew Adams <drew.adams@oracle.com> writes:
>> I use the Bookmarks+ module (perhaps not relevant). I also frequently read
>> PDFs. But when I bookmark a PDF, jumping to it causes it to open within
>> emacs, rather than with my system default viewer. There are many people
>> asking similar questions online but the answers don't seem to fit; I can't
>> use the dired solution of `!` to execute a shell command in this case. Any
>> tips?
>
> Since you use Bookmark+ the answer is yes, you can easily open
> a bookmark that targets a PDF file using any application you like,
> and you have several possibilities:
>
> You can use option `bmkp-default-handlers-for-file-types' to
> control which operation (bookmark handler) to use by default,
> for which file types (e.g. PDF).
>
> `M-x customize-option bmkp-default-handlers-for-file-types'
>
> This is a set of associations (an alist), with each key being
> a regexp matching file names, and with each associated value
> being a Lisp sexp that evaluates to either a shell command
> (a string) or an Emacs function (a symbol or lambda form).
>
> You can think of `bmkp-default-handlers-for-file-types' as
> somewhat analogous to `auto-mode-alist'. But it maps file-name
> patterns to file actions instead of mapping them to buffer
> modes. And it has an effect only when you use certain commands.
>
> The default value of `bmkp-default-handlers-for-file-types'
> is taken from the value of `dired-guess-shell-alist-user', so
> you can, if you prefer, just customize that option. (That
> option comes from standard library `dired-x.el'.)
>
> If `bmkp-default-handlers-for-file-types' specifies no
> matching association for a given file, and if option
> `bmkp-guess-default-handler-for-file-flag' is non-nil,
> then Bookmark+ guesses a shell command to use. It uses
> `dired-guess-shell-alist-default' (first) and your mailcap
> entries (second) to guess.
>
> A bookmark that was created for a file without visiting it
> (e.g., using `C-x p c f' or `C-x p c a') has its `file-handler'
> property set automatically to the handler specified for its
> type by `bmkp-default-handlers-for-file-types'.
>
> If you are on MS Windows, then, in _addition_ to what is
> said above:
>
> * In the `*Bookmark List*' display you can use any of these to
> open bookmarks using associated Windows `Open' applications:
>
> `M-RET' - `bmkp-bmenu-w32-open': this bookmark (on this line)
> `M-mouse-2' - `bmkp-bmenu-w32-open-with-mouse': clicked bookmark
> `M-o' - `bmkp-bmenu-w32-jump-to-marked': this bookmark &
> marked bookmarks
>
> You can still associate particular bookmarks or file types
> with particular shell commands or other programs, via option
> `bmkp-default-handlers-for-file-types'.
>
> But you can also take advantage of the file associations
> that are defined outside Emacs, for Windows. You can thus
> have two different associations for the same file type and
> use either of them whenever you want.
>
> * If you associate action `w32-browser' with a file type in
> `bmkp-default-handlers-for-file-types' then you can use
> command `bmkp-w32-browser-jump' (not bound to a key by
> default) anytime to open a file of that type using the
> Windows `Open' action.
>
> * You can use command `bmkp-jump-to-type' (`C-x j :') and
> input `w32-browser' as the bookmark type, to limit completion
> candidates to bookmarks that are associated with `w32-browser'.
>
> This is all covered in the Bookmark+ doc:
>
> * All of the doc: http://www.emacswiki.org/emacs/BookmarkPlus
>
> * `bmkp-default-handlers-for-file-types':
> http://www.emacswiki.org/emacs/BookmarkPlus#BookmarkingFilesYouCannotVisitWithEmacs
>
> * Using MS Windows file associations:
> http://www.emacswiki.org/emacs/BookmarkPlus#WindowsFileAssociations
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Bookmark a PDF, open in external program
2015-01-31 18:31 ` Drew Adams
2015-01-31 18:49 ` Tory S. Anderson
@ 2015-02-10 18:50 ` Tory S. Anderson
2015-02-10 21:15 ` Drew Adams
1 sibling, 1 reply; 5+ messages in thread
From: Tory S. Anderson @ 2015-02-10 18:50 UTC (permalink / raw)
To: Drew Adams; +Cc: emacs list
I'm using emacs 25.0.5 and bmkp-default-handlers-for-file-types simply isn't working. Here's what I have:
'(bmkp-default-handlers-for-file-types (quote (("\\.pdf$" . "xdg-open"))))
Nonetheless if just opens with find-file (which is breaking for other reasons). Did I get something wrong?
Drew Adams <drew.adams@oracle.com> writes:
>> I use the Bookmarks+ module (perhaps not relevant). I also frequently read
>> PDFs. But when I bookmark a PDF, jumping to it causes it to open within
>> emacs, rather than with my system default viewer. There are many people
>> asking similar questions online but the answers don't seem to fit; I can't
>> use the dired solution of `!` to execute a shell command in this case. Any
>> tips?
>
> Since you use Bookmark+ the answer is yes, you can easily open
> a bookmark that targets a PDF file using any application you like,
> and you have several possibilities:
>
> You can use option `bmkp-default-handlers-for-file-types' to
> control which operation (bookmark handler) to use by default,
> for which file types (e.g. PDF).
>
> `M-x customize-option bmkp-default-handlers-for-file-types'
>
> This is a set of associations (an alist), with each key being
> a regexp matching file names, and with each associated value
> being a Lisp sexp that evaluates to either a shell command
> (a string) or an Emacs function (a symbol or lambda form).
>
> You can think of `bmkp-default-handlers-for-file-types' as
> somewhat analogous to `auto-mode-alist'. But it maps file-name
> patterns to file actions instead of mapping them to buffer
> modes. And it has an effect only when you use certain commands.
>
> The default value of `bmkp-default-handlers-for-file-types'
> is taken from the value of `dired-guess-shell-alist-user', so
> you can, if you prefer, just customize that option. (That
> option comes from standard library `dired-x.el'.)
>
> If `bmkp-default-handlers-for-file-types' specifies no
> matching association for a given file, and if option
> `bmkp-guess-default-handler-for-file-flag' is non-nil,
> then Bookmark+ guesses a shell command to use. It uses
> `dired-guess-shell-alist-default' (first) and your mailcap
> entries (second) to guess.
>
> A bookmark that was created for a file without visiting it
> (e.g., using `C-x p c f' or `C-x p c a') has its `file-handler'
> property set automatically to the handler specified for its
> type by `bmkp-default-handlers-for-file-types'.
>
> If you are on MS Windows, then, in _addition_ to what is
> said above:
>
> * In the `*Bookmark List*' display you can use any of these to
> open bookmarks using associated Windows `Open' applications:
>
> `M-RET' - `bmkp-bmenu-w32-open': this bookmark (on this line)
> `M-mouse-2' - `bmkp-bmenu-w32-open-with-mouse': clicked bookmark
> `M-o' - `bmkp-bmenu-w32-jump-to-marked': this bookmark &
> marked bookmarks
>
> You can still associate particular bookmarks or file types
> with particular shell commands or other programs, via option
> `bmkp-default-handlers-for-file-types'.
>
> But you can also take advantage of the file associations
> that are defined outside Emacs, for Windows. You can thus
> have two different associations for the same file type and
> use either of them whenever you want.
>
> * If you associate action `w32-browser' with a file type in
> `bmkp-default-handlers-for-file-types' then you can use
> command `bmkp-w32-browser-jump' (not bound to a key by
> default) anytime to open a file of that type using the
> Windows `Open' action.
>
> * You can use command `bmkp-jump-to-type' (`C-x j :') and
> input `w32-browser' as the bookmark type, to limit completion
> candidates to bookmarks that are associated with `w32-browser'.
>
> This is all covered in the Bookmark+ doc:
>
> * All of the doc: http://www.emacswiki.org/emacs/BookmarkPlus
>
> * `bmkp-default-handlers-for-file-types':
> http://www.emacswiki.org/emacs/BookmarkPlus#BookmarkingFilesYouCannotVisitWithEmacs
>
> * Using MS Windows file associations:
> http://www.emacswiki.org/emacs/BookmarkPlus#WindowsFileAssociations
^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: Bookmark a PDF, open in external program
2015-02-10 18:50 ` Tory S. Anderson
@ 2015-02-10 21:15 ` Drew Adams
0 siblings, 0 replies; 5+ messages in thread
From: Drew Adams @ 2015-02-10 21:15 UTC (permalink / raw)
To: torys.anderson; +Cc: emacs list
> I'm using emacs 25.0.5 and bmkp-default-handlers-for-file-types simply
> isn't working. Here's what I have:
> '(bmkp-default-handlers-for-file-types (quote (("\\.pdf$" . "xdg-open"))))
>
> Nonetheless if just opens with find-file (which is breaking for other
> reasons). Did I get something wrong?
It's better to follow up off list, I think. You can always report back
to the list with any summary info that you think might help others.
Can you use `xdg-open' otherwise than via a bookmark? Is it installed
on your machine? Is it in your PATH? If not, then that's maybe the
problem.
You can also try another file association, to see if the relevant
Bookmark+ code is working for you in general. I.e., to see whether it is
true that "bmkp-default-handlers-for-file-types simply isn't working."
For example, try adding an association such as this:
("\\.html?$" . browse-url) or this (if you have `w32-browser.el'):
("\\.doc$" . w32-browser). If that works then the problem is likely
with `xdg-open' and not with the Bookmark+ code.
Anyway, try this, if the above suggestion didn't help:
1. Load the Bookmark+ source files (*.el, not *.elc).
2. M-x debug-on-entry bmkp-default-handler-for-file
3. Try to invoke the bookmark in question (to a PDF file).
4. Open the source code for `bmkp-default-handler-for-file' and
`bmkp-default-handler-user' (in bookmark+-1.el) in a separate window
or frame, so you can follow along when you use the debugger (step 5).
5. In the debugger, use `d' to step through the code.
You can use `c' to skip through any step that it is uninteresting.
You can use `e' at any time to evaluate a sexp and see its value.
You can also use `C-h v' etc.
Let me know what you see. Thx.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2015-02-10 21:15 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-31 16:37 Bookmark a PDF, open in external program Tory S. Anderson
2015-01-31 18:31 ` Drew Adams
2015-01-31 18:49 ` Tory S. Anderson
2015-02-10 18:50 ` Tory S. Anderson
2015-02-10 21:15 ` Drew Adams
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).