[Openmcl-devel] paren matching in the editor

Ron Garret ron at flownet.com
Fri Jan 7 10:11:37 PST 2011


On Jan 6, 2011, at 9:10 AM, R. Matthew Emerson wrote:

> 
> On Jan 6, 2011, at 11:57 AM, Tim Bradshaw wrote:
> 
>> Is anyone but me experiencing very odd paren matching in the editor?  What happens for me is that if I type, say
>> 
>> (defun foo ()
>> (let ((x 1))
>>   +
>> 
>> with the cursor marked by "+", then typing closing parens highlights the closing paren itself, not the opening paren.  It stops highlighting them when there would be no corresponding opening paren.
>> 
>> In more complicated situations it seems to leave lots of little highlights over parens which are not related to what I'm currently editing.
>> 
>> I'm running the trunk (1.7-dev-r14556M, 64bit) on OSX 10.6.6: I think it was happening before the possibly slightly ill-advised 10.6.6 upgrade though.
> 
> The way paren highlighting is done was recently changed, in r14490 through r14492.  It sounds like there are some bugs there.
> 
> (The point of the change was to do paren highlighting in a way that would work on Cocotron also.)

The bug is at the end of compute-temporary-attributes.  Until this gets fixed, you can patch it yourself by reverting to the old definition.  Here it is for your convenience, so you don't have to go rooting around in Trac:

(in-package :gui)

(defmethod compute-temporary-attributes ((self hemlock-textstorage-text-view))
  #-cocotron
  (let* ((container (#/textContainer self))
         ;; If there's a containing scroll view, use its contentview         
         ;; Otherwise, just use the current view.
         (scrollview (#/enclosingScrollView self))
         (contentview (if (%null-ptr-p scrollview) self (#/contentView scrollview)))
         (rect (#/bounds contentview))
         (layout (#/layoutManager container))
         (glyph-range (#/glyphRangeForBoundingRect:inTextContainer:
                       layout rect container))
         (char-range (#/characterRangeForGlyphRange:actualGlyphRange:
                      layout glyph-range +null-ptr+))
         (start (ns:ns-range-location char-range))
         (length (ns:ns-range-length char-range)))
    (when (> length 0)
      ;; Remove all temporary attributes from the character range
      (#/removeTemporaryAttribute:forCharacterRange:
       layout #&NSForegroundColorAttributeName char-range)
      (#/removeTemporaryAttribute:forCharacterRange:
       layout #&NSBackgroundColorAttributeName char-range)
      (let* ((ts (#/textStorage self))
             (cache (hemlock-buffer-string-cache (slot-value ts 'hemlock-string)))
             (hi::*current-buffer* (buffer-cache-buffer cache)))
        (multiple-value-bind (start-line start-offset)
                             (update-line-cache-for-index cache start)
          (let* ((end-line (update-line-cache-for-index cache (+ start length))))
            (set-temporary-character-attributes
             layout
             (- start start-offset)
             start-line
             (hi::line-next end-line))))))
    (when (eql #$YES (text-view-paren-highlight-enabled self))
      (let* ((background #&NSBackgroundColorAttributeName)
             (paren-highlight-left (text-view-paren-highlight-left-pos self))
             (paren-highlight-right (text-view-paren-highlight-right-pos self))
             (paren-highlight-color (text-view-paren-highlight-color self))
	     (attrs (#/dictionaryWithObject:forKey: ns:ns-dictionary
						    paren-highlight-color
						    background)))
        (#/addTemporaryAttributes:forCharacterRange:
         layout attrs (ns:make-ns-range paren-highlight-left 1))
        (#/addTemporaryAttributes:forCharacterRange:
         layout attrs (ns:make-ns-range paren-highlight-right 1))))))


More information about the Openmcl-devel mailing list