panel: implement string_file_ext() for extension column display#5069
panel: implement string_file_ext() for extension column display#5069karpovilia wants to merge 1 commit intoMidnightCommander:masterfrom
Conversation
src/filemanager/panel.c
Outdated
| string_file_ext (const file_entry_t *fe, int len) | ||
| { | ||
| const char *ext; | ||
|
|
||
| (void) len; | ||
|
|
||
| ext = extension (fe->fname->str); |
There was a problem hiding this comment.
| string_file_ext (const file_entry_t *fe, int len) | |
| { | |
| const char *ext; | |
| (void) len; | |
| ext = extension (fe->fname->str); | |
| string_file_ext (const file_entry_t *fe, MC_UNUSED int len) | |
| { | |
| const char *ext = extension (fe->fname->str); |
doc/NEWS
Outdated
|
|
||
| - Fixes | ||
|
|
||
| * Extension column in user-defined panel format now displays only the file extension instead of the full filename |
There was a problem hiding this comment.
Please remove; the changelog for the next release is collected on the wiki and updated during the release process.
|
Shouldn't you also add |
|
'basename' might be a misleading terminology to use; see e.g. https://stackoverflow.com/questions/13362022/what-do-you-call-a-file-name-without-the-extension |
The extension panel field used string_file_name as its display callback, showing the full filename instead of just the extension. There was already a TODO comment acknowledging this (// TODO: string_file_ext). Add string_file_ext() which returns only the part after the last dot for regular files, or an empty string for directories and extensionless files. Add string_file_basename() which returns the filename without its extension (without the trailing dot), complementing the extension field. Both fields are documented in the man page. Example user_format: half basename | extension | size | mtime Signed-off-by: Ilia Karpov <iakarpov@edu.hse.ru> Signed-off-by: ki <karpovilia@gmail.com>
0b162e0 to
5fc6ef8
Compare
@egmontkob, thanks! basename (displays the filename without extension) added, news cleared, proposed changes updated. |
|
I still don't quite get where this is going, why it's deemed useful, nor how the details are worked out. You add to the documentation: "For directories and files without an extension, ...". For me, it parses like "For (either directories or files) without an extension, ...". This is not what the code does. What the code does is better described by something like "For directories, and for files without an extension, ...". Why is that, though? Why do you want to handle directories differently? For "dotfiles" ("hidden files") that begin with a dot, the entire filename is treated as the extension. I don't think it's desireable. The entire idea of trying to autodetect the extension is a weak heuristics only. There's Both basename and extension are silently truncated if too long and don't fit in the space. Just like with the full filename, truncation should be denoted and the contents should scroll horizontally for Basename and extension receive equally wide space, even though in practice the basename is usually quite long, while the extension is usually up to 4 characters. That's quite a waste of the often scarce real estate. Would it make sense to make the Extension column be 4 characters narrow (and scrollable, as per the previous point)? Honestly, I'd just remove the current broken "extension" support. What's your story, your use case, why would you find this feature (with its inherently often incorrect guess) useful? |
Proposed changes
The
extensionpanel field usedstring_file_nameas its display callback, showing the full filename instead of just the extension. The code already had a TODO comment acknowledging this (// TODO: string_file_ext).This PR adds two new panel format fields:
extension— displays only the file extension (part after last dot). Empty for directories and extensionless files.basename— displays the filename without extension (without the trailing dot). For directories, identical to the full name.Example format:
half basename | extension | size | mtimeBoth fields are documented in the man page.
Checklist
git commit --amend -smake indent && make check)