From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: John Yates Newsgroups: gmane.emacs.devel Subject: hideshow: two minor tweaks Date: Wed, 8 Feb 2012 00:46:10 -0500 Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: dough.gmane.org 1328679983 19333 80.91.229.3 (8 Feb 2012 05:46:23 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 8 Feb 2012 05:46:23 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Feb 08 06:46:22 2012 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Rv0MD-0001CM-N2 for ged-emacs-devel@m.gmane.org; Wed, 08 Feb 2012 06:46:17 +0100 Original-Received: from localhost ([::1]:59083 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rv0MC-0005dG-V2 for ged-emacs-devel@m.gmane.org; Wed, 08 Feb 2012 00:46:16 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]:44916) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rv0M9-0005d0-UX for emacs-devel@gnu.org; Wed, 08 Feb 2012 00:46:14 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Rv0M8-0004nR-VJ for emacs-devel@gnu.org; Wed, 08 Feb 2012 00:46:13 -0500 Original-Received: from mail-iy0-f169.google.com ([209.85.210.169]:41315) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rv0M8-0004nJ-KP for emacs-devel@gnu.org; Wed, 08 Feb 2012 00:46:12 -0500 Original-Received: by iagz16 with SMTP id z16so461818iag.0 for ; Tue, 07 Feb 2012 21:46:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:sender:date:x-google-sender-auth:message-id:subject :from:to:content-type; bh=9TIg6v/ffumy8q/yYRI6/PRbJKIVsbJhh3hz9rFvvwE=; b=lVfsjYiGiPO0/3lYpYqW5lsssiG6L5IRp9bGl1d7MFPoOzwfSbWjaNpWoRdhxMWxoq LVwb+yQjQaYM291qlzMd4AH0CzFMZ86SAXr4OFSnpxmqGG5RBoFAGwXG9NMMZO1KdrtG KqSRDxH6Pt4hefJ4svAz0vwHwIVawSfQl8M70= Original-Received: by 10.50.188.234 with SMTP id gd10mr8019906igc.29.1328679970839; Tue, 07 Feb 2012 21:46:10 -0800 (PST) Original-Received: by 10.231.108.74 with HTTP; Tue, 7 Feb 2012 21:46:10 -0800 (PST) X-Google-Sender-Auth: SVopmvqvUXVJQWMYi4SnQRSAAjE X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.210.169 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:148350 Archived-At: At present hs-show-block expands a hidden comment block irrespective of where the cursor happens to be on the collapsed comment line. It also leaves the cursor position unchanged. By contrast hs-hide-block's handling of comment blocks exhibits two rough edges: (1) It fails to recognize a comment block if the cursor is in white space to the left. Fixed by having hs-inside-comment-p skip leading white space. (2) It always positions the cursor at the first character of the collapsed comment. Fixed by having hs-hide-comment-region maintian the cursor column if possible. --- cur/hideshow.el +++ fix/hideshow.el @@ -552,11 +552,13 @@ (defun hs-hide-comment-region (beg end &optional repos-end) "Hide a region from BEG to END, marking it as a comment. Optional arg REPOS-END means reposition at end." - (let ((beg-eol (progn (goto-char beg) (line-end-position))) + (let ((goal-col (current-column)) + (beg-bol (progn (goto-char beg) (line-beginning-position))) + (beg-eol (line-end-position)) (end-eol (progn (goto-char end) (line-end-position)))) (hs-discard-overlays beg-eol end-eol) - (hs-make-overlay beg-eol end-eol 'comment beg end)) - (goto-char (if repos-end end beg))) + (hs-make-overlay beg-eol end-eol 'comment beg end) + (goto-char (if repos-end end (min end (+ beg-bol goal-col)))))) (defun hs-hide-block-at-point (&optional end comment-reg) "Hide block if on block beginning. @@ -607,6 +609,7 @@ ;; forward comment, and see if we are inside, then extend ;; forward and backward as long as we have comments (let ((q (point))) + (skip-chars-forward "[:blank:]") (when (or (looking-at hs-c-start-regexp) (re-search-backward hs-c-start-regexp (point-min) t)) ;; first get to the beginning of this comment... I use the following fragment to explore the behavior of with the cursor left of comment start, on comment start, and within the comment text. /john /* adjl ajdlf ajdfla */ int a; /* ajdklfj ** ajsdfljl ** adsfjll */ int b; /* adhfkah * adslj * ajdlfk */ int c; // asdjflj // ajdlfj // ajsdflj int d; // adjfla // jalsdfjla // jlasd int e; // asdfjl // ajdflj // jasdfjl int f;