Coder Social home page Coder Social logo

[bug] `airline-position-segment` not displaying `mode-line-position`, important for some major modes about telephone-line HOT 6 OPEN

leonardo-cavegliacurtil avatar leonardo-cavegliacurtil commented on July 17, 2024
[bug] `airline-position-segment` not displaying `mode-line-position`, important for some major modes

from telephone-line.

Comments (6)

leonardo-cavegliacurtil avatar leonardo-cavegliacurtil commented on July 17, 2024

Here is my proposed version: if it matches the regex /L\d+\s*$/, it uses the previous "airline" code; otherwise, it uses mode-line-position.

Ideally, I'd use a smarted regex like /^\s*\w+\s*L\d+\s*$/, which should match only the patterns seen in text buffers (e.g. Top L40 or 5% L40), but I can't get them to work properly.

Tested and apparently working, both with text buffers and with PDFView buffers. Can someone check that this code isn't garbage? I have no idea what I'm doing with elisp. :)

(telephone-line-defsegment* telephone-line-airline-position-segment (&optional lines columns)
  "Position segment imitating vim-airline's appearance. Optional args set padding on lines/columns."
  (let* ((l (number-to-string (if lines lines 4)))
         (c (number-to-string (if columns columns 3))))
    (if (eq major-mode 'paradox-menu-mode)
        (telephone-line-raw mode-line-front-space t)
      (if (string-match-p "L[0-9]+\s*$" (telephone-line-raw mode-line-position t))
	  `((-3 "%p") ,(concat " %" l "l"
			       ":%" c (if (bound-and-true-p column-number-indicator-zero-based) "c" "C")))
	mode-line-position)
)))

from telephone-line.

leonardo-cavegliacurtil avatar leonardo-cavegliacurtil commented on July 17, 2024

I got it to work with this regex /^[\w\s%]*L\d+\s*$/, which should match all standard positions in text buffers.

(telephone-line-defsegment* telephone-line-airline-position-segment (&optional lines columns)
  "Position segment imitating vim-airline's appearance. Optional args set padding on lines/columns."
  (let* ((l (number-to-string (if lines lines 4)))
         (c (number-to-string (if columns columns 3))))
    (if (eq major-mode 'paradox-menu-mode)
        (telephone-line-raw mode-line-front-space t)
      (if (string-match-p "^[[:alnum:]\s%]*L[0-9]+\s*$" (telephone-line-raw mode-line-position t))
	  `((-3 "%p") ,(concat " %" l "l"
			       ":%" c (if (bound-and-true-p column-number-indicator-zero-based) "c" "C")))
	mode-line-position)
)))

I'm not sure if it's a clean solution to match against (telephone-line-raw mode-line-position t). But in case the code is sound, I have a branch ready for a pull.

from telephone-line.

dbordak avatar dbordak commented on July 17, 2024

This sounds correct, but I don't remember best practices on elisp regex...

from telephone-line.

leonardo-cavegliacurtil avatar leonardo-cavegliacurtil commented on July 17, 2024

Any updates on this? What is exactly that is missing?

from telephone-line.

dbordak avatar dbordak commented on July 17, 2024

I think selecting on major mode would be a cleaner solution, even if it means that it needs to be expanded in the future. I can't tell conclusively all the text formats that various modes use (i.e. it's possible that some of them would match the given regex, somehow), but on the other hand, modes which overwrite this value are probably going to be relatively few (likely only the ones which aren't rendering text, like pdfview).

EDIT: also another argument for, there's already a major-mode check in this function. Also, it'd be immediately obvious to anyone looking at the function why this check is necessary, vs the regex probably needing a line comment at least.

Something like this?

(telephone-line-defsegment* telephone-line-airline-position-segment (&optional lines columns)
  "Position segment imitating vim-airline's appearance. Optional args set padding on lines/columns."
  (let* ((l (number-to-string (if lines lines 4)))
         (c (number-to-string (if columns columns 3))))
    (cond
      ((eq major-mode 'paradox-menu-mode) (telephone-line-raw mode-line-front-space t))
      ((eq major-mode 'pdf-view-mode) (telephone-line-raw mode-line-position t))
      (t `((-3 "%p") ,(concat " %" l "l"
                              ":%" c (if (bound-and-true-p column-number-indicator-zero-based) "c" "C")))))))

from telephone-line.

leonardo-cavegliacurtil avatar leonardo-cavegliacurtil commented on July 17, 2024

That works just fine, and yeah, the regex does seem like a bit of a workaround.
The reason why I originally said that a major mode check seems "less clean" is that it's a hardcoded switch, that will inevitably end up growing.
I also found another mode that requires an exception, scad-preview-mode, from the scad-mode package.
I tested your code, added the following line, and it works as expected.

      ((eq major-mode 'scad-preview-mode) (telephone-line-raw mode-line-position t))

Screenshot_20240507_184715


I'd propose to expose a customizable list of major modes, defaulting to those we know so far.
While not necessary, it would be a more permanent solution; although, at that point, it would also call for many other customizable lists and strings throughout the package.
I don't want to perturb the project too much, so it's up to you on whether that's worth considering.

That aside, the issue is to be considered solved, when this is patch is on MELPA.

from telephone-line.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.