1

I have a reasonably large buffer, whose first five characters i like to make as comment (this is a simplified problem of a larger issue, so bear with me).

Buffer contents:

;;some comment text, whose property needs to be changed.
(add-text-properties 0 7 
                     '(comment t face highlight))

When i do eval-buffer, it throws error as, Args out of range: 0, 7.

Since the buffer has more than five characters, why does add-text-properties throw out of range error?

2

The first point in the buffer is 1, not 0 -- that is why the example produces an error message stating Args out of range . . .. The doc-string for add-text-properties states that START and END are buffer positions, unless the optional argument OBJECT is a string. Since there is no optional OBJECT argument in the example, we are dealing with strictly buffer positions.

The first line of code, (ignore "hello" "bye" "chalo"), serves no purpose and detracts from the issue.

add-text-properties is a built-in function in `C source code'.

(add-text-properties START END PROPERTIES &optional OBJECT)

Add properties to the text from START to END.
The third argument PROPERTIES is a property list
specifying the property values to add.  If the optional fourth argument
OBJECT is a buffer (or nil, which means the current buffer),
START and END are buffer positions (integers or markers).
If OBJECT is a string, START and END are 0-based indices into it.
Return t if any property value actually changed, nil otherwise.
  • changed the sample code to be simpler... thanks, lawlist.. – Madhavan Sep 19 '16 at 7:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.