! Please note that this is a snapshot of our old Bugzilla server, which is read only since May 29, 2020. Please go to gitlab.xfce.org for our new server !
mousepad bug (regarding syntax highlighting and creating new file)
Status:
RESOLVED: FIXED
Severity:
critical
Product:
Mousepad
Component:
General

Comments

Description iscream 2013-05-31 10:37:18 CEST
* Now talking on #xfce
* Topic for #xfce is: Xfce 4.10 released! Get it -> http://www.xfce.org/download | Translate? http://translations.xfce.org/ | Ask your question and then BE PATIENT AND IDLE FOR A WHILE
* Topic for #xfce set by sarts at Thu Jul 26 20:52:13 2012
* #xfce :http://www.xfce.org
<fchmmr> is this the official channel?
* t_s_o has quit (Remote host closed the connection)
<fchmmr> i fonud a bug in mousepad 0.3.0
<fchmmr> when syntax highlighting is enabled (im using kate theme),
<fchmmr> if you do ctrl+n (make new doc) then save as anyname.php,
<fchmmr> syntax highlighting dont show up
<fchmmr> i had to close it first and then open it again (in mousepad)
* freedomrun has quit (Quit: So long and thanks for all the fish)
* bullgard4 has quit (Remote host closed the connection)
* freedomrun (~freedomru@unaffiliated/freedomrun) has joined #xfce
* eithel (~eithel@95.233.246.198) has joined #xfce
<killermoehre> fchmmr: file this bug at bugzilla.xfce.org
<fchmmr> thx
<fchmmr> i will go there
Comment 1 iscream 2013-05-31 10:49:48 CEST
cleaner description:

open a PHP file with syntax colors turned on, it works ok.

however, if you create a new document within mousepad then save it as a *.php (without closing) then start writing code, it doesn't show with syntax colours until you close the document and open it again.
Comment 2 Andre Miranda editbugs 2013-10-11 05:40:30 CEST
Created attachment 5179 
patch

Misbehavior confirmed.
The attached path solves the problem.
Comment 3 alister.hood 2013-11-19 05:00:26 CET
I think you need a more complicated patch, perhaps to first check whether you've manually set the filetype, and do nothing if you have.

With the current patch, regardless of whether you are creating a new file or editing an existing one, if you have manually set the filetype (by clicking document->filetype->..., or from the status bar) to something different from what is autodetected, it overrides your choice every time you save the file.

Note that there is a minor issue which is kind of related: 
1. open Mousepad without opening an existing file
2. click File-new
3. in each tab, look at Document->filetype, and it will be "None" (the same as what is in the status bar)
4. open an existing file of some sort.
5. click File-new
6. repeat step 3: all the files will show up as whatever type of file you opened in step 4 (but the file type in the status bar will always be correct).
Comment 4 alister.hood 2013-11-19 05:08:04 CET
> perhaps to first check whether you've manually set the filetype, and do nothing if you have.

But this approach would still cause a problem if you manually set the filetype to "None", unless it can tell that you did so.
Comment 5 alister.hood 2013-11-19 06:12:50 CET
Another issue which could possibly be considered a separate bug is that there is no syntax highlighting when you use "File>New from template".  In this case the correct behaviour is obvious, so I guess the fix should be reasonably straightforward ;)
Comment 6 Andre Miranda editbugs 2013-11-25 17:24:26 CET
(In reply to alister.hood from comment #3)
> I think you need a more complicated patch, perhaps to first check whether
> you've manually set the filetype, and do nothing if you have.

I agree with you, but it's just like Joel Spolsky says "500% effort to handle 1% of the cases". It's kind of weird if someone select Ruby syntax and write Python code. I've just tested Notepad++ and it's dumb just like my patch. Let's see what other folks think about it.
Comment 7 alister.hood 2013-11-25 23:28:12 CET
The problem will more commonly be when mousepad guesses a filetype "None". Try this with your patch:
- Open a file in /usr/share/gtksourceview-2.0/language-specs
- It isn't recognised as xml (at least on my machine), so tell mousepad that it is xml.
- Every time you save the file the syntax highlighting disappears again.
Comment 8 Andre Miranda editbugs 2013-11-25 23:42:22 CET
(In reply to alister.hood from comment #7)
> The problem will more commonly be when mousepad guesses a filetype "None".
> Try this with your patch:
> - Open a file in /usr/share/gtksourceview-2.0/language-specs
> - It isn't recognised as xml (at least on my machine), so tell mousepad that
> it is xml.
> - Every time you save the file the syntax highlighting disappears again.

Well, in this case if the file has no extension, then Mousepad shouldn't do anything. What do you think?
Comment 9 alister.hood 2013-11-26 01:18:25 CET
When you *open* an existing file and it doesn't detect the type then it will still need to set File: None
So you would need some more code anyway, so that it just doesn't set File: None after *saving* a file.

And I'm inclined to think the case you are trying to solve is part of Joel's 1%.
i.e. someone starts coding but doesn't set the language, and then when they save the file they suddenly expect syntax highlighting.  Wouldn't they normally set the language earlier if they need syntax highlighting?

Personally I would make solving the issue I raised in comment 5 more of a priority :)
Comment 10 Matthew Brush editbugs 2014-07-14 21:17:32 CEST
I fixed most of this stuff I think.

The main bug was fixed in http://git.xfce.org/apps/mousepad/commit/?id=87ae5a08165461c01317719a3cea4c73a5f07dce, trying to take into consideration whether the user set the language themselves.

The bug from Comment #4 about some of the language UI not updating when a language is set or tabs are switched was fixed in http://git.xfce.org/apps/mousepad/commit/?id=f113f6c88f191cbb7cd68493fa992cd111311b12.

The bug from Comment #5 about the language not being set for template files was fixed in http://git.xfce.org/apps/mousepad/commit/?id=f113f6c88f191cbb7cd68493fa992cd111311b12, although it just uses the normal guessing mechanism as we don't really know/store the language of template files AFAICT.

Please test to confirm the fixes if possible.
Comment 11 Andre Miranda editbugs 2014-07-15 02:51:29 CEST
I guess this is fixed.
Maybe Alister can test it thoroughly :)
Comment 12 alister.hood 2014-07-15 04:14:42 CEST
I can't actually build at the moment:

mousepad-window.c:1038:58: error: ‘mousepad_window_ui’ undeclared (first use in this function)
   gtk_ui_manager_add_ui_from_string (window->ui_manager, mousepad_window_ui, mousepad_window_ui_length, NULL);
                                                          ^
mousepad-window.c:1038:58: note: each undeclared identifier is reported only once for each function it appears in
mousepad-window.c:1038:78: error: ‘mousepad_window_ui_length’ undeclared (first use in this function)
   gtk_ui_manager_add_ui_from_string (window->ui_manager, mousepad_window_ui, mousepad_window_ui_length, NULL);
Comment 13 Matthew Brush editbugs 2014-07-15 04:58:38 CEST
That stuff comes from the mousepad-window-ui.h file, despite being checked into Git, is also (re)generated from mousepad-window-ui.xml, but only when --enable-maintainer-mode is passed to configure script AFAIK.
Comment 14 alister.hood 2014-07-15 08:29:40 CEST
OK, it is generally good, there is just the corner case:
- File->New from Template
- File->Save as
- Neglect to add the appropriate file extension, and the syntax highlighting disappears.
Comment 15 Matthew Brush editbugs 2014-07-15 09:52:02 CEST
I wonder if a successful guessing of a new template file's language should be treated the same as the user explicitly setting the filetype, so it's not re-guessed on Save As? This sounds simple to implement at least :)

I think the file extension in save(as) dialog is a bit of a separate issue, but I'll look at it too.
Comment 16 alister.hood 2014-07-15 12:33:18 CEST
> I wonder if a successful guessing of a new template file's language should be treated the same as the user explicitly setting the filetype, so it's not re-guessed on Save As?

Yes, that's what I thought would make sense.

Bug #10134

Reported by:
iscream
Reported on: 2013-05-31
Last modified on: 2014-07-15

People

Assignee:
Matthew Brush
CC List:
6 users

Version

Target Milestone:
Mousepad 0.2.x

Attachments

patch (523 bytes, patch)
2013-10-11 05:40 CEST , Andre Miranda
andreldm : review? ( matt )

Additional information