Xfce Forum

Sub domains
 

You are not logged in.

#1 2022-07-07 10:14:20

jt1122
Member
Registered: 2021-03-26
Posts: 245

Mousepad adding words to highlight

Hi,

Can additional words be defined for highlighting in mousepad?.

For example, Octave has do - until loops, "do" is currently shown in bold but "until" not.

Thanks

Offline

#2 2022-07-07 11:24:30

KBar
Member
Registered: 2021-11-05
Posts: 689

Re: Mousepad adding words to highlight

It is provided by the GtkSource library. Depending on what version of it you have, the language specs are located in /usr/share/gtksourceview-*. You can perform a quick search like so:

find /usr/share/gtksourceview-*/ -iname '*octave*'

A quick look suggests that until is defined as a keyword in both gtksourceview-3.0 and gtksourceview-4, and indeed, it's highlighted in Mousepad 0.4.2.


Remember to edit the subject of your topic to include the [SOLVED] tag once you're satisfied with the answers or have found a solution (in which case, don't forget to share it as well), so that other members of the community can quickly refer to it and save their time. Pretty please! tongue

Offline

#3 2022-07-07 11:52:47

jt1122
Member
Registered: 2021-03-26
Posts: 245

Re: Mousepad adding words to highlight

Thanks.

I'm using MP 0.5.8 .

As mentioned "do" is shown in bold but "until" isn't.
How can this be fixed?.

Last edited by jt1122 (2022-07-07 12:36:25)

Offline

#4 2022-07-07 12:50:36

KBar
Member
Registered: 2021-11-05
Posts: 689

Re: Mousepad adding words to highlight

Ok. Can you post the relevant part of octave.lang?

sed -n '209,249p' /usr/share/gtksourceview-4/language-specs/octave.lang

Remember to edit the subject of your topic to include the [SOLVED] tag once you're satisfied with the answers or have found a solution (in which case, don't forget to share it as well), so that other members of the community can quickly refer to it and save their time. Pretty please! tongue

Offline

#5 2022-07-07 12:56:00

jt1122
Member
Registered: 2021-03-26
Posts: 245

Re: Mousepad adding words to highlight

Sure:

       <context id="octave-matlab-keyword" style-ref="keyword">
          <!--
            Octave and Matlab have already implemented most of each others keywords
            but not all. Both Octave and Matlab are still missing keywords from the
            other. As such, this block only has the keywords already implemented in
            both. When adding a new keyword, make sure you place it on the right
            place.
          -->
          <keyword>break</keyword>
          <keyword>case</keyword>
          <keyword>catch</keyword>
          <keyword>classdef</keyword>
          <keyword>continue</keyword>
          <keyword>do</keyword>
          <keyword>else</keyword>
          <keyword>elseif</keyword>
          <keyword>end</keyword>
          <keyword>enumeration</keyword>
          <keyword>events</keyword>
          <keyword>for</keyword>
          <keyword>function</keyword>
          <keyword>if</keyword>
          <keyword>methods</keyword>
          <keyword>otherwise</keyword>
          <keyword>parfor</keyword>
          <keyword>properties</keyword>
          <keyword>return</keyword>
          <keyword>switch</keyword>
          <keyword>try</keyword>
          <keyword>until</keyword>
          <keyword>varargin</keyword>
          <keyword>varargout</keyword>
          <keyword>while</keyword>
        </context>
      </include>
    </context>

    <context id="builtin" style-ref="builtin">
      <!--  If any of these is between "." it's a struct.  -->
      <prefix>(?&lt;!\.)\%[</prefix>
      <suffix>\%](?!\.)</suffix>

Offline

#6 2022-07-07 13:06:56

KBar
Member
Registered: 2021-11-05
Posts: 689

Re: Mousepad adding words to highlight

Can you check if that file is read by removing the line for do? You can also comment it out, if you'd like:

<!--  <keyword>do</keyword>  -->

By any chance, did you compile Mousepad from source?


Remember to edit the subject of your topic to include the [SOLVED] tag once you're satisfied with the answers or have found a solution (in which case, don't forget to share it as well), so that other members of the community can quickly refer to it and save their time. Pretty please! tongue

Offline

#7 2022-07-07 13:12:47

jt1122
Member
Registered: 2021-03-26
Posts: 245

Re: Mousepad adding words to highlight

Thanks.

I've changed the file, no difference.

Didn't compile from source, simple apt install.

Last edited by jt1122 (2022-07-07 13:13:01)

Offline

#8 2022-07-07 13:23:07

KBar
Member
Registered: 2021-11-05
Posts: 689

Re: Mousepad adding words to highlight

By "no difference" do you mean that the do keyword got shown even after you commented it out? Did you close your active Mousepad windows and then reopen them?

Is the keyword not recognized in all of your source files or in one specific file?

What's the file extension that you use for them? Can you post the part of the source code that's not getting picked up?

Also, just to make sure: have you selected a color scheme in Preferences and have you set filetype to Octave?


Remember to edit the subject of your topic to include the [SOLVED] tag once you're satisfied with the answers or have found a solution (in which case, don't forget to share it as well), so that other members of the community can quickly refer to it and save their time. Pretty please! tongue

Offline

#9 2022-07-07 14:25:15

jt1122
Member
Registered: 2021-03-26
Posts: 245

Re: Mousepad adding words to highlight

"no difference" means "until" still doesn't show in bold.

Offline

#10 2022-07-08 06:02:24

KBar
Member
Registered: 2021-11-05
Posts: 689

Re: Mousepad adding words to highlight

My apologies for not being clear, but what we tried to do is to check whether the file /usr/share/gtksourceview-4/language-specs/octave.lang is read at all. After you've commented out or removed the line for the do keyword (forget about until for a moment), did it affect its appearance in your code? Was it still being highlighted in bold or not? Determining this would provide us more hints as to what's actually happening.

Since the keywords are properly defined in the langspec file, my suspicions are: 1) you're not setting the filetype to the correct one in Document > Filetype > Scientific > Octave; or 2) you have unterminated quotes on the same line as the until keyword (double-check your code).

Hopefully, I've made myself clear now.


Remember to edit the subject of your topic to include the [SOLVED] tag once you're satisfied with the answers or have found a solution (in which case, don't forget to share it as well), so that other members of the community can quickly refer to it and save their time. Pretty please! tongue

Offline

#11 2022-07-08 12:49:23

Tamaranch
Member
Registered: 2020-12-31
Posts: 321

Re: Mousepad adding words to highlight

Instead of editing system files, you can copy them in ~/.local/share/gtksourceview-4/language-specs (to be created if needed) and do your tests there.
`until` is properly highlighted for me though, and it should be for you given what you show in #5.
Don't you already have something in ~/.local/share/gtksourceview-4/language-specs that overrides it?

Offline

#12 2022-07-08 15:56:42

jt1122
Member
Registered: 2021-03-26
Posts: 245

Re: Mousepad adding words to highlight

Thanks for the replies.

I've manually set the document type: Document->File Type->Scientific->Matlab
& not everything is highlighted as expected.

But doesn't MP recognize it's an Octave/Matlab file to "auto-select" the proper highlighting?.

Offline

#13 2022-07-08 16:21:59

Tamaranch
Member
Registered: 2020-12-31
Posts: 321

Re: Mousepad adding words to highlight

This is difficult: Matlab is a sub-language of Octave, so it is not always possible to distinguish. If the `.m` extension is present, GSV favors Octave internally I think. Otherwise Mousepad uses `g_content_type_guess()` which detects Matlab.

Be careful though: if you force the language recognition to Matlab, Mousepad will remember your choice and stay on it afterwards (if the recent file history is not disabled).

But why put Matlab, when Octave is the right language?

Offline

#14 2022-07-08 16:30:42

jt1122
Member
Registered: 2021-03-26
Posts: 245

Re: Mousepad adding words to highlight

Thanks.
I see there's a separate entry for Octave so I've chosen that now (and bold text is as expected).

But my question remains - Octave also has a ".m" suffix. isn't that auto-recognized by MP?

Offline

#15 2022-07-08 17:22:04

Tamaranch
Member
Registered: 2020-12-31
Posts: 321

Re: Mousepad adding words to highlight

As I tried to explain above, Mousepad and its dependencies try to do what they can about it. For me (on Arch Linux) `.m` files are automatically recognized as Octave files, but it may depend on the version of GSV, GLib and shared-mime-info, at least.

Offline

#16 2022-07-08 17:52:04

jt1122
Member
Registered: 2021-03-26
Posts: 245

Re: Mousepad adding words to highlight

Thanks. so there are no config files to tweak to ensure ".m" is recognized?.

Offline

#17 2022-07-08 18:57:35

Tamaranch
Member
Registered: 2020-12-31
Posts: 321

Re: Mousepad adding words to highlight

No I don't think so, but here's what you can do to force recognition:

mkdir -p ~/.local/share/gtksourceview-4/language-specs
cp /usr/share/gtksourceview-4/language-specs/octave.lang ~/.local/share/gtksourceview-4/language-specs/matlab.lang
sed -i 's/id="octave"/id="matlab"/' ~/.local/share/gtksourceview-4/language-specs/matlab.lang

Offline

Registered users online in this topic: 0, guests: 1
[Bot] ClaudeBot

Board footer

Powered by FluxBB
Modified by Visman

[ Generated in 0.011 seconds, 7 queries executed - Memory usage: 597.84 KiB (Peak: 614.32 KiB) ]