Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7012903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:19:00+00:00 2026-05-27T22:19:00+00:00

In a Gedit plugin written in Python, I can get the offset of the

  • 0

In a Gedit plugin written in Python, I can get the offset of the beginning of the current line with

document = window.get_active_document()
offset = document.get_iter_at_mark(document.get_insert())

How could I get the offset of the end of this same line? For now I am using a workaround: I get the offset of the next line and subtract the offset of the desired line from it, and subtract 1 (with an special case treated for the last line). Is there a better way of doing it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:19:01+00:00Added an answer on May 27, 2026 at 10:19 pm

    A bit late, I know, but better late than never. I am running gedit 3.2.3 and I don’t know how much these things change from one version to another, but this works for me:

    line_types = {"cr-lf": '\r\n',
                  "lf": '\n',
                  "cr": '\r'}
    document = window.get_active_document()
    newline = line_types[document.get_newline_type().value_nick]
    insert_mark = document.get_insert()
    offset = document.get_iter_at_mark(insert_mark)
    line = offset.get_line()
    # we subtract 1 because get_chars_in_line() counts the newline character
    # there is a special case with the last line if it doesn't have a newline at the end
    # we deal with that later
    line_length = offset.get_chars_in_line() - len(newline)
    end_of_line = document.get_iter_at_line_offset(line, line_length)
    if end_of_line.get_char() != newline[0]:
        end_of_line = document.get_iter_at_offset(end_of_line.get_offset()+len(newline))
    # if the above code is correct this should select from the current insert point
    # to the end of line
    document.move_mark(insert_mark, end_of_line)
    

    Edit 1: Was not accounting for the case where the file wasn’t terminated by a newline character

    Edit 2: Account for different definitions of the end of line

    PS: Whether this or your currently solution is “cleaner” or “better”, I don’t know, I guess that’s subjective.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm learning Python and I try to use Python Markdown in a gedit plugin.
I'm working on a Gedit plugin using Python (and PyGTK) and I really havent'
We are building a plugin for Gedit 3 using python. The idea is to
The gedit external tools plugin allows tools to apply to only one or more
I'm just starting out learning python with GEdit plus various plugins as my IDE.
I use gedit in Ubuntu (dual monitor) for web development in python,html,js. its working
I need some good gedit theme, where did I get one? Thanks Adam Ramadhan
I'm writing my first gedit plugin, a directory browser for the sidebar. Show sidepanel
I created a Gedit 2 plugin which adds an item to a menu as
I'm writing a gedit 3 plugin , something similar to phsilva's PyLint plugin ,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.