#314 Template wildcard for "filename without extension"

open
nobody
None
5
2013-07-26
2009-09-24
Cousteau
No

This would be useful for example on Java or Matlab files, where the name of the main class/function must match the file name (without extension).
filetype.java may then have a line like this: "public class {filenamenoext} {" instead of the current "public class {untitled} {"

Related

Feature Requests: #314

Discussion

  • Fabio Ticconi

    Fabio Ticconi - 2013-07-26

    I'm trying, out of fun, to implement this "feature" (on the master branch on GIT). However I'm having problems understanding how the "second conversion" works for {filename}.

    For example, let's take this line in templates.c, function "templates_replace_common":

    "{filename}", shortname,
    

    when the template.ext is loaded the wildcard is substituted with untitled.ext, and when the file it's saved and named "filename", untitled.ext becomes filename.ext.

    Now, by substituting the above with:

    "{filename}", utils_remove_ext_from_filename(shortname),
    

    the wildcard gets substituted with "untitled" without .ext, and when the file is saved is just left the same.

    It seems like templates_replace_common is NOT called again when the file is saved.

    Therefore, there must be another function that gets called on document-save and trasforms untitled.ext into the filename.

    But I'm struggling to find it. Any help?

     
  • Lex Trotman

    Lex Trotman - 2013-07-26

    On 26 July 2013 10:29, Lex Trotman elextr@gmail.com wrote:

    On 26 July 2013 10:05, Fabio Ticconi fabioticconi@users.sf.net wrote:

    I'm trying, out of fun, to implement this "feature" (on the master branch
    on GIT). However I'm having problems understanding how the "second
    conversion" works for {filename}.

    For example, let's take this line in templates.c, function
    "templates_replace_common":

    "{filename}", shortname,

    when the template.ext is loaded the wildcard is substituted with
    untitled.ext, and when the file it's saved and named "filename",
    untitled.ext becomes filename.ext.

    Now, by substituting the above with:

    "{filename}", utils_remove_ext_from_filename(shortname),

    the wildcard gets substituted with "untitled" without .ext, and when the
    file is saved is just left the same.

    It seems like templates_replace_common is NOT called again when the file
    is saved.

    Therefore, there must be another function that gets called on
    document-save and trasforms untitled.ext into the filename.

    Yup, in document.c, called only from save-as "replace_header_filename()"
    searches the first three lines for the regex /untitled.\w+/ and replaces
    it with the filename. Note the ext gets changed because it may have been
    changed by the user (since this is on save-as).

    You can't do this in the template since you don't have the filename yet.

    PS suggest you implement the feature request as a plugin that catches the
    "document-before-save" signal and does the modification, thats what its
    for. Make sure it only happens to Java files too.

     
  • Lex Trotman

    Lex Trotman - 2013-07-26

    On 26 July 2013 10:05, Fabio Ticconi fabioticconi@users.sf.net wrote:

    I'm trying, out of fun, to implement this "feature" (on the master branch
    on GIT). However I'm having problems understanding how the "second
    conversion" works for {filename}.

    For example, let's take this line in templates.c, function
    "templates_replace_common":

    "{filename}", shortname,

    when the template.ext is loaded the wildcard is substituted with
    untitled.ext, and when the file it's saved and named "filename",
    untitled.ext becomes filename.ext.

    Now, by substituting the above with:

    "{filename}", utils_remove_ext_from_filename(shortname),

    the wildcard gets substituted with "untitled" without .ext, and when the
    file is saved is just left the same.

    It seems like templates_replace_common is NOT called again when the file
    is saved.

    Therefore, there must be another function that gets called on
    document-save and trasforms untitled.ext into the filename.

    Yup, in document.c, called only from save-as "replace_header_filename()"
    searches the first three lines for the regex /untitled.\w+/ and replaces
    it with the filename. Note the ext gets changed because it may have been
    changed by the user (since this is on save-as).

    You can't do this in the template since you don't have the filename yet.

    But I'm struggling to find it. Any help?

    Status: open
    Created: Thu Sep 24, 2009 10:01 AM UTC by Cousteau
    Last Updated: Thu Sep 24, 2009 10:01 AM UTC
    Owner: nobody

    This would be useful for example on Java or Matlab files, where the name
    of the main class/function must match the file name (without extension).
    filetype.java may then have a line like this: "public class
    {filenamenoext} {" instead of the current "public class {untitled} {"


    Sent from sourceforge.net because you indicated interest in
    https://sourceforge.net/p/geany/feature-requests/314/

    To unsubscribe from further messages, please visit
    https://sourceforge.net/auth/subscriptions/

     

    Related

    Feature Requests: #314

  • Fabio Ticconi

    Fabio Ticconi - 2013-07-26

    Ok yes, it makes sense. I'll try with a plugin then.

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks