Print to PDF (and open in browser)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Print to PDF (and open in browser)

slackyman76
Hello (sorry for my poor English),

I need to send a lot of emails (50-70) from lists everyday and I had found a good way to save my time pasting the list to Writer, exporting it to pdf, opening pdf in chromium and going directly to Gmail when I click on the links.

Then I started to learn Vim (few months ago) and I found a new way to do the job with one command: in my .vimrc I put the following remap

"PRINT TO PDF / PRINT AND OPEN TO CHROMIUM
nmap <C-Home> :ha > newfile.ps <cr> :! ps2pdf newfile.ps<cr>:! rm newfile.ps<cr>
nmap <C-S-Home> :ha > newfile.ps <cr> :! ps2pdf newfile.ps<cr>:! rm newfile.ps && chromium newfile.pdf<cr>

So, in the first line I put the command to create a PDF.
In the second line I create PDF and open it to chromium (Debian is my OS, and Chromium is my default and favorite browser).
Then, as above, I click on the addresses in PDF document and go directly to Gmail, which is my default email "client" (ok, it's not a client but I set it to be the default email).

The only problem is that I have to rename "newfile" to a different name everytime. It's not a dramatic issue indeed, but...

My questions:

1) Is there a more elegant or effective way to do the same things?

2) Is there a way to open an email address from VIM and land in Gmail without creating  a PDF? In Vim I open urls using gx but it doesn't work with email addresses.

Thank you! :-)

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Print to PDF (and open in browser)

Nikolay Aleksandrovich Pavlov
2018-01-27 13:29 GMT+03:00  <[hidden email]>:

> Hello (sorry for my poor English),
>
> I need to send a lot of emails (50-70) from lists everyday and I had found a good way to save my time pasting the list to Writer, exporting it to pdf, opening pdf in chromium and going directly to Gmail when I click on the links.
>
> Then I started to learn Vim (few months ago) and I found a new way to do the job with one command: in my .vimrc I put the following remap
>
> "PRINT TO PDF / PRINT AND OPEN TO CHROMIUM
> nmap <C-Home> :ha > newfile.ps <cr> :! ps2pdf newfile.ps<cr>:! rm newfile.ps<cr>
> nmap <C-S-Home> :ha > newfile.ps <cr> :! ps2pdf newfile.ps<cr>:! rm newfile.ps && chromium newfile.pdf<cr>
>
> So, in the first line I put the command to create a PDF.
> In the second line I create PDF and open it to chromium (Debian is my OS, and Chromium is my default and favorite browser).
> Then, as above, I click on the addresses in PDF document and go directly to Gmail, which is my default email "client" (ok, it's not a client but I set it to be the default email).
>
> The only problem is that I have to rename "newfile" to a different name everytime. It's not a dramatic issue indeed, but...
>
> My questions:
>
> 1) Is there a more elegant or effective way to do the same things?
>
> 2) Is there a way to open an email address from VIM and land in Gmail without creating  a PDF? In Vim I open urls using gx but it doesn't work with email addresses.

[hidden email] looks much like going to bar.baz via http protocol (or
https in some cases due to HSTS), using user foo: you may check
https://en.wikipedia.org/wiki/URL#Syntax: side from omitting a
protocol this is a valid URL interpretation and http/https is the
default one. You should be able to do what is needed if you add
`mailto:` before emails so chromium would know what exactly you need.

>
> Thank you! :-)
>
> --
> --
> You received this message from the "vim_use" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php
>
> ---
> You received this message because you are subscribed to the Google Groups "vim_use" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
> For more options, visit https://groups.google.com/d/optout.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Print to PDF (and open in browser)

Tim Chase
In reply to this post by slackyman76
On 2018-01-27 02:29, [hidden email] wrote:
> "PRINT TO PDF / PRINT AND OPEN TO CHROMIUM
> nmap <C-Home> :ha > newfile.ps <cr> :! ps2pdf newfile.ps<cr>:! rm
> newfile.ps<cr>
> nmap <C-S-Home> :ha > newfile.ps <cr> :! ps2pdf newfile.ps<cr>:!
> rm newfile.ps && chromium newfile.pdf<cr>
[snip]
> The only problem is that I have to rename "newfile" to a different
> name everytime. It's not a dramatic issue indeed, but...
>
> My questions:
>
> 1) Is there a more elegant or effective way to do the same things?

I guess it depends on which aspects you find inelegant of ineffective.

You could then take advantage of the 'printexpr' so ":hardcopy" alone
does everything you need.  You can read the gritty details at

  :help :hardcopy
  :h 'printexpr'
  :h pexpr-option

Particularly the bit in that last one about simplifying things with a
function.

Either way, wrapping it in a function might clean up the code,
something like (untested)

  function! PrintFile(fname, ...)
    call system('ps2pdf '. a:fname)
    call delete(a:fname)
    if a:0
      call system('chromium ' . substitute(a:fname, '.ps$', '.pdf', '')
    endif
    return v:shell_error
  endfunc
  nmap <c-home> :set printexpr=PrintFile(v:fname_in) <bar> ha<cr>
  nmap <c-s-home> :set printexpr=PrintFile(v:fname_in, 1) <bar> ha<cr>

By default my local copy of vim seems to name the "1.pdf", "3.pdf",
etc.  Not sure if there's any sort of guaranteed in the sequence,
though I imagine they just auto-increment a bit. Not sure if it's
smart about the auto-generated names if more than one instance of vim
is running concurrently in the same directory.

You could also prompt for an output filename or auto-generate one
using the current timestamp:

  function! PrintFile(fname, ...)
    let l:outname=strftime('%Y%m%d_%H%M%S.pdf)
    call system('ps2pdf '. a:fname . l:outname)
    call delete(a:fname)
    if a:0
      call system('chromium ' . a:outname)
    endif
    return v:shell_error
  endfunc
  nmap <c-home> :set printexpr=PrintFile(v:fname_in) <bar> ha<cr>
  nmap <c-s-home> :set printexpr=PrintFile(v:fname_in, 1) <bar> ha<cr>

> 2) Is there a way to open an email address from VIM and land in
> Gmail without creating  a PDF? In Vim I open urls using gx but it
> doesn't work with email addresses.

Sorry, can't help much here as this is a Gmail-URL and browser sort
of thing external to vim.

-tim






--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.