SublimeText / LaTeXTools

LaTeX plugin for Sublime Text
https://latextools.readthedocs.io/
2.01k stars 366 forks source link

Can't open image with shortcut C-l-o in v3.6.0 #624

Closed Gabriel-p closed 8 years ago

Gabriel-p commented 8 years ago

I'm running elementary OS 0.3 (Freya) and I use Viewnior as my default image viewer.

I added the following to my settings file:

// ------------------------------------------------------------------
// Opening files included into the tex source code
// ------------------------------------------------------------------

    // image types you use in latex
    // these types will be used for autocompletion and 
    // opening of included images, when no extension is written
    "image_types": ["png", "pdf", "jpg", "jpeg", "eps"],

    // the commands to open image files. The extensions will be matched from top to bottom.
    // If no extension is given, all extensions will be matched.
    // If there is no match the image will be opened with Sublime Text.
    // the extension:
    //      can either be a string for one extension
    //      or an array of string to match more than one extensions.
    // the command:
    //      can be the name to start the programm. The image file will be passed
    //          as the argument.
    //      can be a string as a command with args:
    //          e.g. "open -a PixelMator", in this case the file will be appended
    //          if the position is relevant use "$file" in the string
    //          e.g. "open -a PixelMator $file"
    //          this will be substituted by the path to the file
    "open_image_command": {
        "linux": [
            {
                // open pdf documents with evince
                "extension": "pdf",
                "command": "evince"
            }
            // uncomment these lines to open all other images with the default programm
            ,
            {
                "command": "viewnior"
            }
        ]
    },

but this just opens the app with no image. I tried "command": "viewnior $file" but it does the same thing.

ig0774 commented 8 years ago

Can you grab the console output from when you press C-l-o? Also, which version of ST are you using?

Gabriel-p commented 8 years ago

This is the console at first load (I'm using Sublime 3, build 3083):

DPI scale: 1
startup, version: 3083 linux x64 channel: stable
executable: /opt/sublime_text/sublime_text
working dir: /home/gabriel
packages path: /home/gabriel/.config/sublime-text-3/Packages
state path: /home/gabriel/.config/sublime-text-3/Local
zip path: /opt/sublime_text/Packages
zip path: /home/gabriel/.config/sublime-text-3/Installed Packages
ignored_packages: ["Vintage"]
pre session restore time: 0.321052
loading dictionary Packages/Dictionaries/English (British).dic
startup time: 0.734682
first paint time: 0.745848
reloading plugin Default.block
reloading plugin Default.comment
reloading plugin Default.copy_path
reloading plugin Default.delete_word
reloading plugin Default.detect_indentation
reloading plugin Default.duplicate_line
reloading plugin Default.echo
reloading plugin Default.exec
reloading plugin Default.fold
reloading plugin Default.font
reloading plugin Default.goto_line
reloading plugin Default.history_list
reloading plugin Default.indentation
reloading plugin Default.kill_ring
reloading plugin Default.mark
reloading plugin Default.new_templates
reloading plugin Default.open_context_url
reloading plugin Default.open_file_settings
reloading plugin Default.open_in_browser
reloading plugin Default.pane
reloading plugin Default.paragraph
reloading plugin Default.paste_from_history
reloading plugin Default.quick_panel
reloading plugin Default.save_on_focus_lost
reloading plugin Default.scroll
reloading plugin Default.set_unsaved_view_name
reloading plugin Default.side_bar
reloading plugin Default.sort
reloading plugin Default.swap_line
reloading plugin Default.switch_file
reloading plugin Default.symbol
reloading plugin Default.transform
reloading plugin Default.transpose
reloading plugin Default.trim_trailing_white_space
reloading plugin CSS.css_completions
reloading plugin Diff.diff
reloading plugin HTML.encode_html_entities
reloading plugin HTML.html_completions
reloading plugin 0_package_control_loader.00-package_control
reloading plugin 0_package_control_loader.01-pygments
reloading plugin 0_package_control_loader.01-ssl-linux
Package Control: Linux SSL: successfully loaded _ssl module for libssl.so.1.0.0
reloading plugin 0_package_control_loader.02-bz2
reloading plugin 0_package_control_loader.50-pyyaml
reloading plugin AlignTab.aligner
reloading plugin AlignTab.aligntab
reloading plugin AlignTab.hist
reloading plugin AlignTab.parser
reloading plugin AlignTab.table
reloading plugin AlignTab.wclen
reloading plugin Alignment.Alignment
reloading plugin All Autocomplete.all_views_completions
reloading plugin AutoPEP8.sublautopep8
reloading plugin AutoWrap.autowrap
reloading plugin Dictionaries.Dictionaries
reloading plugin Git.add
reloading plugin Git.annotate
reloading plugin Git.commit
reloading plugin Git.diff
reloading plugin Git.flow
reloading plugin Git.git
reloading plugin Git.history
reloading plugin Git.repo
reloading plugin Git.stash
reloading plugin Git.status
reloading plugin Git.statusbar
reloading plugin GitGutter.git_gutter
reloading plugin GitGutter.git_gutter_change
reloading plugin GitGutter.git_gutter_compare
reloading plugin GitGutter.git_gutter_events
reloading plugin GitGutter.git_gutter_handler
reloading plugin GitGutter.git_helper
reloading plugin GitGutter.view_collection
reloading plugin LaTeX Word Count.WordCount
reloading plugin Markdown Preview.MarkdownPreview
reloading plugin Markdown Preview.helper
reloading plugin Markdown Preview.markdown_settings
reloading plugin Markdown Preview.markdown_wrapper
reloading plugin MaxPane.layouts_doc
reloading plugin MaxPane.max_pane
reloading plugin Package Control.1_reloader
reloading plugin Package Control.2_bootstrap
reloading plugin Package Control.Package Control
reloading plugin SideBarEnhancements.SideBar
reloading plugin SideBarEnhancements.SideBarAPI
reloading plugin SideBarEnhancements.SideBarDefaultDisable
reloading plugin Sublime Bookmarks.bookmark
reloading plugin Sublime Bookmarks.bookmarkWatcher
reloading plugin Sublime Bookmarks.common
reloading plugin Sublime Bookmarks.sublimebookmark
reloading plugin Sublime Bookmarks.ui
reloading plugin Sublime Bookmarks.visibilityHandler
reloading plugin SublimeLinter-chktex.linter
SublimeLinter: chktex linter loaded 
reloading plugin View In Browser.ViewInBrowserCommand
reloading plugin WordHighlight.word_highlight
reloading plugin Wrap Plus.wrap_plus
reloading plugin pastebin-sublime-plugin.pastebin
reloading plugin requirementstxt.requirements
reloading plugin Anaconda.anaconda
reloading plugin Anaconda.version
reloading plugin LaTeXTools.change_environment
reloading plugin LaTeXTools.delete_temp_files
reloading plugin LaTeXTools.getRegion
reloading plugin LaTeXTools.getTeXRoot
reloading plugin LaTeXTools.jumpToPDF
reloading plugin LaTeXTools.jumpto_tex_file
reloading plugin LaTeXTools.kpsewhich
reloading plugin LaTeXTools.latexCommand
reloading plugin LaTeXTools.latexDocumentationViewer
reloading plugin LaTeXTools.latexEnvCloser
reloading plugin LaTeXTools.latexEnvironment
reloading plugin LaTeXTools.latexFillAll
reloading plugin LaTeXTools.latex_cite_completions
reloading plugin LaTeXTools.latex_cwl_completions
reloading plugin LaTeXTools.latex_input_completions
reloading plugin LaTeXTools.latex_installed_packages
reloading plugin LaTeXTools.latex_ref_cite_completions
reloading plugin LaTeXTools.latex_ref_completions
reloading plugin LaTeXTools.makePDF
reloading plugin LaTeXTools.migrate
reloading plugin LaTeXTools.parseTeXlog
reloading plugin LaTeXTools.texMacro
reloading plugin LaTeXTools.texSections
reloading plugin LaTeXTools.texSyntaxListener
reloading plugin LaTeXTools.toggle_auto
reloading plugin LaTeXTools.toggle_focus
reloading plugin LaTeXTools.toggle_fwdsync
reloading plugin LaTeXTools.toggle_show
reloading plugin LaTeXTools.viewPDF
reloading plugin OmniMarkupPreviewer.OmniMarkupPreviewer
reloading plugin PlainTasks.PlainTasks
reloading plugin SublimeLinter.commands
reloading plugin SublimeLinter.sublimelinter
reloading plugin SublimeREPL.__init__
reloading plugin SublimeREPL.completions
reloading plugin SublimeREPL.lang_integration
reloading plugin SublimeREPL.run_existing_command
reloading plugin SublimeREPL.sublimerepl
reloading plugin SublimeREPL.sublimerepl_build_system_hack
reloading plugin SublimeREPL.text_transfer
plugins loaded
SublimeLinter: debug mode: off 
SublimeLinter: chktex activated: /usr/bin/chktex 
OmniMarkupPreviewer: [INFO] Bottle v0.11.6 server starting up...
OmniMarkupPreviewer: [INFO] Listening on http://127.0.0.1:51004/
OmniMarkupPreviewer: [INFO] Loaded renderer: OrgRenderer
OmniMarkupPreviewer: [INFO] Loaded renderer: AsciiDocRenderer
OmniMarkupPreviewer: [INFO] Loaded renderer: PodRenderer
OmniMarkupPreviewer: [INFO] Loaded renderer: TextileRenderer
OmniMarkupPreviewer: [INFO] Loaded renderer: CreoleRenderer
OmniMarkupPreviewer: [INFO] Loaded renderer: RstRenderer
OmniMarkupPreviewer: [INFO] Loaded renderer: MediaWikiRenderer
OmniMarkupPreviewer: [INFO] Loaded renderer: MarkdownRenderer
OmniMarkupPreviewer: [INFO] Loaded renderer: RDocRenderer
/home/gabriel/.config/sublime-text-3
LOADING BOOKMARKS
Package Control: Skipping automatic upgrade, last run at 2015-12-13 10:59:26, next run at 2015-12-13 11:59:26 or after

This is what I see after C-l-o with "command": "viewnior" and "command": "viewnior $file" in the settings:

Jumpto image file 'test.png'
Commands: '[{'command': 'evince', 'extension': 'pdf'}, {'command': 'viewnior'}]'
Open File: '/home/gabriel/Descargas/test.png'
{'command': 'evince', 'extension': 'pdf'}
{'command': 'viewnior'}
RUN: ['viewnior', '/home/gabriel/Descargas/test.png']
Jumpto image file 'test.png'
Commands: '[{'command': 'evince', 'extension': 'pdf'}, {'command': 'viewnior $file'}]'
Open File: '/home/gabriel/Descargas/test.png'
{'command': 'evince', 'extension': 'pdf'}
{'command': 'viewnior $file'}
RUN: ['viewnior', '/home/gabriel/Descargas/test.png']
r-stein commented 8 years ago

This seems to be correct. Can you try to run the command

viewnior /home/gabriel/Descargas/test.png

in your shell. This is the command, which is executed (via subprocess.Popen).

ig0774 commented 8 years ago

This seems to me like the kind of issue that can arise with the shell setting on the subprocess... It opens the viewer, so it's finding the command alright, but it doesn't open the file because somehow the argument is missing or mangled.

@Gabriel-p: could you run both viewnior /home/gabriel/Descargas/test.png, as @r-stein requested and /bin/sh -c viewnior /home/gabriel/Descargas/test.png which (as I read the Python docs) is basically what the subprocess tries to run on Unix when shell=True and let us know the results?

Gabriel-p commented 8 years ago

@ig0774 the first command opens the image properly. The second one (/bin/sh ...) opens only the Viewnior app with no loaded image (ie: the same behavior as this package).

r-stein commented 8 years ago

It seems it would be the best solution just to drop the shell argument. I think I added it before splitting the argument string into an array.

@Gabriel-p could you to open the console in Sublime Text View>Show Console and paste

import subprocess; subprocess.Popen(['viewnior', '/home/gabriel/Descargas/test.png'])

This should open the viewer and show the file.

Gabriel-p commented 8 years ago

@r-stein yep, that line works fine.

r-stein commented 8 years ago

I made a pull request to fix it. Until then you can temporary fix it on your computer. To do this paste this in your ST console to open the file:

window.open_file(sublime.packages_path() + "/LaTeXTools/jumpto_tex_file.py")

And then remove the shell-argument in line 180 or set it to False.