From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Carlos Pita Newsgroups: gmane.emacs.bugs Subject: bug#19761: python.el: improved hideshow mode support Date: Tue, 3 Feb 2015 19:21:53 -0300 Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: ger.gmane.org 1423002554 31249 80.91.229.3 (3 Feb 2015 22:29:14 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 3 Feb 2015 22:29:14 +0000 (UTC) Cc: galli.87@gmail.com To: 19761@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Feb 03 23:29:13 2015 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1YIly3-0002LW-DF for geb-bug-gnu-emacs@m.gmane.org; Tue, 03 Feb 2015 23:29:11 +0100 Original-Received: from localhost ([::1]:33681 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YIly2-0002o8-Tt for geb-bug-gnu-emacs@m.gmane.org; Tue, 03 Feb 2015 17:29:10 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:56788) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YIlxv-0002mE-ES for bug-gnu-emacs@gnu.org; Tue, 03 Feb 2015 17:29:08 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YIlxu-0000on-Fi for bug-gnu-emacs@gnu.org; Tue, 03 Feb 2015 17:29:03 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:41966) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YIlxu-0000oi-C0 for bug-gnu-emacs@gnu.org; Tue, 03 Feb 2015 17:29:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1YIlxu-00074b-48; Tue, 03 Feb 2015 17:29:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Carlos Pita Original-Sender: "Debbugs-submit" Resent-CC: galli.87@gmail.com, bug-gnu-emacs@gnu.org Resent-Date: Tue, 03 Feb 2015 22:29:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 19761 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org X-Debbugs-Original-Xcc: galli.87@gmail.com Original-Received: via spool by submit@debbugs.gnu.org id=B.142300253327170 (code B ref -1); Tue, 03 Feb 2015 22:29:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 3 Feb 2015 22:28:53 +0000 Original-Received: from localhost ([127.0.0.1]:33205 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YIlxl-00074A-78 for submit@debbugs.gnu.org; Tue, 03 Feb 2015 17:28:53 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:54990) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YIlxj-00073y-SJ for submit@debbugs.gnu.org; Tue, 03 Feb 2015 17:28:52 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YIlxd-0000mo-Iz for submit@debbugs.gnu.org; Tue, 03 Feb 2015 17:28:46 -0500 Original-Received: from lists.gnu.org ([208.118.235.17]:58291) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YIlxd-0000mk-Ge for submit@debbugs.gnu.org; Tue, 03 Feb 2015 17:28:45 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:56707) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YIlxc-0002iN-JO for bug-gnu-emacs@gnu.org; Tue, 03 Feb 2015 17:28:45 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YIlxb-0000mJ-Lg for bug-gnu-emacs@gnu.org; Tue, 03 Feb 2015 17:28:44 -0500 Original-Received: from mail-lb0-x230.google.com ([2a00:1450:4010:c04::230]:51022) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YIlxb-0000mC-ES for bug-gnu-emacs@gnu.org; Tue, 03 Feb 2015 17:28:43 -0500 Original-Received: by mail-lb0-f176.google.com with SMTP id z12so41222445lbi.7 for ; Tue, 03 Feb 2015 14:28:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to:content-type; bh=5UMkOE2Xsq9DPT5Li9wCiHFpY/AaUNEldcAC4Po6rJQ=; b=xEsPwk/bfQr7zUVt4e2GpRKe68HceoAQWZBljD+FBe7jWXmWOint+sXyF9rvuaYP+V Q3a1bFtDKER0QGTp9NJKhbgO5RFp8pTJJjBnxSG3KWx5ybIVtO0r85hY7uSc8T1hqk1p T+KwwAPtLBHXvcjFxr1xNNGVDuuqYWsHPe6VGBh6GVfi9wne5EOIawYCaDvDa64+Q6C3 yIEPHbQlVRA4hiOdStjStX0iJ/uvz8xfE8tWA1ty1VcSZ6EaNHmAiReXU/B8rpzLJise Z7ke6mbrbsiZVQbdlxozVX9gE225T22rAyJZGJtYVSSrl9F/pqyp13+KIl1L16gDMJau 9NBw== X-Received: by 10.112.218.8 with SMTP id pc8mr26750668lbc.16.1423002133580; Tue, 03 Feb 2015 14:22:13 -0800 (PST) Original-Received: by 10.112.124.202 with HTTP; Tue, 3 Feb 2015 14:21:53 -0800 (PST) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:99021 Archived-At: X-Debbugs-CC: galli.87@gmail.com Tags: patch I've found two issues with the current hs configuration: 1) The hs-block-start-regexp wants to anchor at the beginning of line. At least, this doesn't behave well with hs-hide-level-recursive. Try C-c @ C-l on the line after the class statement below. The problem is that the point is not always at the beginning of line when the regexp is evaluated by hs. 2) The hs-forward-sexp-func is python-nav-end-of-defun. This is fine as far as the function is separated by a blank line from the code that follows it. Otherwise the closed fold is joined with the line immediately following it. Try C-c @ C-h on the nested def below. This is easily fixed going one char back when the point is not left in an empty line after python-nav-end-of-defun. So after the changes the new hs configuration is: (add-to-list 'hs-special-modes-alist `(python-mode "\\s-*\\(?:def\\|class\\)\\>" nil "#" ,(lambda (_arg) (python-nav-end-of-defun) (unless (python-info-current-line-empty-p) (backward-char))) nil)) Here is the (real life) example mentioned above: class PivotReader: def __init__(self, file, num_cols): self._pr_file = open(file) if type(file) is str else file self._pr_reader = csv.reader(self._pr_file) header = next(self._pr_reader) self._pr_cols = {col: i for i, col in enumerate(header)} self._pr_nums = [col in num_cols for col in header] self._pr_vals = None def next_row(self): try: self._pr_vals = next(self._pr_reader) return True except: return False def __enter__(self): return self def __exit__(self, type, value, tb): self._pr_file.close() def __getattr__(self, col): return self[col] def __getitem__(self, cols): def get(col): idx = self._pr_cols[col] val = self._pr_vals[idx] num = self._pr_nums[idx] return float(val) if num else val if type(cols) is str: return get(cols) else: return tuple(map(get, cols))