Author Topic: How to open file at cursor ?  (Read 1180 times)

jcelle

  • Senior Community Member
  • Posts: 205
  • Hero Points: 5
How to open file at cursor ?
« on: May 05, 2020, 02:20:31 pm »
Hello,
I am a user of STD version of SlickEdit and evaluating PRO.
I am desperately trying to find a way to find a way to open a file whose name is appearing in the code (open file at cursor).
Does that exist ?

Sample code where it can be useful (PHP):
Code: [Select]
include( 'foo.php' );
While my cursor is somewhere in the 'foo.php' string I would like to be able to open that file the same way SE would try to open it if I was typing 'foo.php' in the enhanced openfile dialog box.


Thanks and regards.
Jerome

Dennis

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 3660
  • Hero Points: 483
Re: How to open file at cursor ?
« Reply #1 on: May 05, 2020, 04:43:07 pm »
Did you try Ctrl+Dot?  (Kind of the standard way to jump from a symbol to a location).

jcelle

  • Senior Community Member
  • Posts: 205
  • Hero Points: 5
Re: How to open file at cursor ?
« Reply #2 on: May 05, 2020, 05:08:00 pm »
Hi Dennis,
I guess you are referring to 'push-tag'  ? There is no ctrl+dot on french keyboards (you need to press shift to get a dot).
I have however remapped push-tag to another key: it interprets the name of the file as a symbol to look up and I get get "no symbols found matching XXX".
I am sure I am not doing things properly but don't know where to look for...
Thanks for your reply.
Jerome

Dennis

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 3660
  • Hero Points: 483
Re: How to open file at cursor ?
« Reply #3 on: May 05, 2020, 05:19:09 pm »
I just tested it with PHP, and it worked correctly.

PHP is a tricky language, my guess is you are not even in PHP mode, but HTML, since PHP is normally just a script embedded in HTML.  But, of course, frequently a .php file only has PHP code, and though it is considered good form to have the enclosing <?php tag, some programmers dispense with doing that.

Try going to Document > Select Mode ... (it should show either PHP or HTML), and select PHP.  If you are in HTML and the embedded PHP is correctly recognized, then it should show "Select Mode (HTML)..." and underneath that, "PHP Options..." indicating that the current embedded language type is PHP.  You can also tell immediately if you are in the correct language mode by whether or not it is color coded properly.  "include" would be colored as a keyword, 'foo.php' would be in string color.

jcelle

  • Senior Community Member
  • Posts: 205
  • Hero Points: 5
Re: How to open file at cursor ?
« Reply #4 on: May 05, 2020, 06:22:32 pm »
Hi Dennis, i'll check tomorrow. Do you confirm that the function to invoke is push-tag ?

Dennis

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 3660
  • Hero Points: 483
Re: How to open file at cursor ?
« Reply #5 on: May 05, 2020, 07:05:36 pm »
Definitely, push-tag.  You can verify what key it is bound to by doing a "where-is push-tag" from the SlickEdit command line.

You can also try "cursor-error" in this case but push-tag is a more general solution for code navigation.

jcelle

  • Senior Community Member
  • Posts: 205
  • Hero Points: 5
Re: How to open file at cursor ?
« Reply #6 on: May 06, 2020, 04:46:46 am »
So push-tag works fine for simple file names like include( 'bar.php' ).
It gets confused for path names like include( '$-bar.php' ) => "no symbols found match bar" : interprets hyphen.
However cursor-error works !
I have created this macro to bind to ctrl+; (that's the french ctrl+dot)
Code: [Select]
   if( 0 == cursor_error() )
   {
      push_bookmark();
   }
   else
   {
      push_tag();
   }
Thanks so much for your precious advice Dennis, I would never have guessed cursor_error by myself !

jcelle

  • Senior Community Member
  • Posts: 205
  • Hero Points: 5
Re: How to open file at cursor ?
« Reply #7 on: May 06, 2020, 02:53:21 pm »
mmh, it looks like cursor_error() has some kind of undocumented behavior:
if it does not find any file it prompts with a "find file" dialog box (it has a control to browse directories).
I have to press ESC to get rid of that dialog box, then cursor_error() exits with an error code and falls back properly to push_tag().
Do you think some parameter can be passed to cursor_error() to make it fail silently (the doc does not mention any parameter) ?

Dennis

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 3660
  • Hero Points: 483
Re: How to open file at cursor ?
« Reply #8 on: May 06, 2020, 03:02:41 pm »
Sorry, no, cursor-error does not have a silent mode.