Comments (6)
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.
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.
This sounds correct, but I don't remember best practices on elisp regex...
from telephone-line.
Any updates on this? What is exactly that is missing?
from telephone-line.
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.
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))
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)
- Separator not rendering correctly when window is inactive. HOT 2
- Org-clock segment possible? HOT 1
- Rendering errors HOT 1
- Gap after airline segment HOT 3
- Optionally don't render segments if they are empty? HOT 1
- The mode line cannot display color
- hud segment rendering errors in terminal Emacs HOT 1
- Add support for project.el ? HOT 5
- Looking to apply airline-theme colors using telephone-line
- How can suppress the smiley face (`: )`) on the right corner?
- I'm too dumb: passing arguments to segments? HOT 3
- Some `mode-line` elements do not respect `telephone-line-accent-active`
- Error during redisplay: (eval (telephone-line-separator-render telephone-line-gradient
- Support for colors when using meow
- Right margin incorrect for proportional-width fonts
- Telephone line is slow to update HOT 1
- `(fn FACE)"]) telephone-line-tan-hollow-right 'evil)) signaled (wrong-type-argument number-or-marker-p nil)`
- Issue with face for telephone-line-major-mode-segment in elisp major mode HOT 2
- Just installed it in ubuntu emacs 29, and i ged a log of warnings?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from telephone-line.