├── .dir-locals.el ├── .elpaignore ├── .github ├── FUNDING.yml ├── ISSUE_TEMPLATE │ ├── bug_report.md │ ├── custom.md │ └── feature_request.md ├── PULL_REQUEST_TEMPLATE.md └── workflows │ ├── ci.yml │ └── news.yml ├── .gitignore ├── CONTRIBUTING.md ├── Cask ├── HISTORY.md ├── LICENSE ├── NEWS.md ├── README.md ├── test ├── test-helper.el └── topspace-test.el └── topspace.el /.dir-locals.el: -------------------------------------------------------------------------------- 1 | ((emacs-lisp-mode 2 | (bug-reference-url-format . "https://github.com/trevorpogue/topspace/issues/%s") 3 | (bug-reference-bug-regexp . "#\\(?2:[[:digit:]]+\\)") 4 | (indent-tabs-mode . nil) 5 | (fill-column . 80) 6 | (sentence-end-double-space . t) 7 | (emacs-lisp-docstring-fill-column . 75) 8 | (checkdoc-symbol-words . ("top-level" "major-mode" "macroexpand-all" "print-level" "print-length")) 9 | (checkdoc-package-keywords-flag) 10 | (checkdoc-arguments-in-order-flag) 11 | (checkdoc-verb-check-experimental-flag))) 12 | -------------------------------------------------------------------------------- /.elpaignore: -------------------------------------------------------------------------------- 1 | .github 2 | .gitignore 3 | test 4 | Cask 5 | CONTRIBUTING.md 6 | HISTORY.md 7 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: trevorpogue # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry 13 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 14 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | 11 | 12 | **Describe the bug** 13 | A clear and concise description of what the bug is. 14 | 15 | **To Reproduce** 16 | Steps to reproduce the behavior: 17 | 18 | *Example:* 19 | 1. Open Emacs 20 | 2. Run this exact combination of commands '....' 21 | 3. See error 22 | 23 | **Expected behavior** 24 | A clear and concise description of what you expected to happen. 25 | 26 | **Screenshots** 27 | If applicable, add screenshots to help explain your problem. 28 | 29 | **Desktop (please complete the following information):** 30 | - OS: [e.g. iOS] 31 | - Browser [e.g. chrome, safari] 32 | - Version [e.g. 22] 33 | 34 | **Smartphone (please complete the following information):** 35 | - Device: [e.g. iPhone6] 36 | - OS: [e.g. iOS8.1] 37 | - Browser [e.g. stock browser, safari] 38 | - Version [e.g. 22] 39 | 40 | ### topspace version information 41 | 42 | ### Emacs version 43 | 44 | *Example: 24.5* (use C-h C-a to see it) 45 | 46 | **Additional context** 47 | Add any other context about the problem here. 48 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/custom.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Custom issue template 3 | about: Describe this issue template's purpose here. 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | 11 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | 11 | 12 | **Is your feature request related to a problem? Please describe.** 13 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 14 | 15 | **Describe the solution you'd like** 16 | A clear and concise description of what you want to happen. 17 | 18 | **Describe alternatives you've considered** 19 | A clear and concise description of any alternative solutions or features you've considered. 20 | 21 | **Additional context** 22 | Add any other context or screenshots about the feature request here. 23 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ----------------- 7 | 8 | ### Checklist 9 | 10 | 11 | 12 | - [ ] I have read the topspace [contributing guidelines](https://github.com/trevorpogue/topspace/blob/main/CONTRIBUTING.md) 13 | - [ ] I have added tests (if possible) to cover my change(s) 14 | - [ ] My changes follow the [Emacs Lisp conventions](https://www.gnu.org/software/emacs/manual/html_node/elisp/Tips.html) and the [Emacs Lisp Style Guide](https://github.com/bbatsov/emacs-lisp-style-guide) 15 | - [ ] I've used the latest version of [package-lint](https://github.com/purcell/package-lint) to check for packaging issues, and addressed its feedback 16 | - [ ] The new code is not generating bytecode warnings 17 | - [ ] I've updated the readme (if adding/changing user-visible functionality) 18 | - [ ] I have confirmed some of these without doing them (this box shouldn't be marked) 19 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: [ push, pull_request ] 4 | jobs: 5 | test: 6 | runs-on: ubuntu-latest 7 | strategy: 8 | matrix: 9 | emacs_version: 10 | - 25.1 11 | - 26.1 12 | - 27.1 13 | - 28.1 14 | - snapshot 15 | steps: 16 | - uses: purcell/setup-emacs@master 17 | with: 18 | version: ${{ matrix.emacs_version }} 19 | - uses: conao3/setup-cask@master 20 | - uses: actions/checkout@v2 21 | - name: CI 22 | env: 23 | COVERALLS_FLAG_NAME: Emacs ${{ matrix.emacs_version }} 24 | COVERALLS_PARALLEL: 1 25 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 26 | run: | 27 | cask install 28 | cask exec buttercup -L . 29 | finalize: 30 | runs-on: ubuntu-latest 31 | if: always() 32 | needs: test 33 | steps: 34 | - run: curl "https://coveralls.io/webhook?repo_name=$GITHUB_REPOSITORY&repo_token=${{ secrets.GITHUB_TOKEN }}" -d "payload[build_num]=$GITHUB_RUN_NUMBER&payload[status]=done" 35 | -------------------------------------------------------------------------------- /.github/workflows/news.yml: -------------------------------------------------------------------------------- 1 | name: News 2 | on: 3 | push: 4 | branches: 5 | - '*' 6 | release: 7 | types: 8 | - created 9 | jobs: 10 | changelog: 11 | runs-on: ubuntu-20.04 12 | 13 | steps: 14 | - uses: actions/checkout@v3 15 | 16 | - name: "✏️ Generate news" 17 | uses: heinrichreimer/github-changelog-generator-action@v2.3 18 | with: 19 | token: ${{ secrets.GITHUB_TOKEN }} 20 | sinceTag: v0.1.2 21 | headerLabel: '# History of user-visible changes' 22 | output: NEWS.md 23 | base: HISTORY.md 24 | issues: no 25 | # futureRelease: v0.3.1 26 | 27 | - name: Commit changes 28 | uses: stefanzweifel/git-auto-commit-action@v4 29 | with: 30 | commit_message: Update NEWS.md 31 | file_pattern: NEWS.md 32 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.~undo-tree~ 2 | .projectile 3 | *.elc 4 | .cask 5 | Eldev 6 | .eldev 7 | topspace.log 8 | \#*\# 9 | coverage/ 10 | cask-run 11 | test/director/ 12 | TODO -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Contributions are welcome! Please [open an issue][1] 4 | if you find a bug, have a feature request, or have any suggestions for 5 | the project at all. 6 | Also feel free to make pull requests yourself instead of issues, 7 | or make pull requests for any existing unresolved issues. 8 | Try to follow the following guidelines if you open an issue or pull request: 9 | 10 | ## Issue reporting 11 | 12 | * Check that the issue has not already been reported. 13 | * Check that the issue has not already been fixed in the latest code 14 | (a.k.a. `main`). 15 | * Be clear, concise and precise in your description of the problem. 16 | * Open an issue with a descriptive title and a summary in grammatically correct, 17 | complete sentences. 18 | * Include any relevant code to the issue summary. 19 | * If you're reporting performance issues it'd be nice if you added some profiling data (Emacs has a built-in profiler). 20 | 21 | ## Pull requests 22 | 23 | * Add tests (if possible) to cover your change(s) 24 | * Follow the [Emacs Lisp conventions](https://www.gnu.org/software/emacs/manual/html_node/elisp/Tips.html) and the [Emacs Lisp Style Guide](https://github.com/bbatsov/emacs-lisp-style-guide) 25 | * Read [how to properly contribute to open source projects on Github][2]. 26 | * Use a topic branch to easily amend a pull request later, if necessary. 27 | * Write [good commit messages][3]. 28 | * Mention related tickets in the commit messages (e.g. `[Fix #N] Add missing autoload cookies`) 29 | * Use the same coding conventions as the rest of the project. 30 | * Verify your Emacs Lisp code with `checkdoc` (C-c ? d). 31 | * Open a [pull request][4] that relates to *only* one subject with a clear title 32 | and description in grammatically correct, complete sentences. 33 | 34 | ## Running Tests 35 | Check [ci.yml][5] to see all the details for the testing frameworks being used, the Emacs versions being tested, and the command(s) required to run the tests. 36 | TLDR: Cask and buttercup are used for testing and can be run like so: 37 | 38 | ``` 39 | cask install 40 | cask exec buttercup -L . 41 | ``` 42 | 43 | ## Copyright Assignment 44 | This package is subject to the same [Copyright Assignment](https://www.gnu.org/prep/maintain/html_node/Copyright-Papers.html) policy as 45 | GNU Emacs and all other packages in [GNU ELPA](https://elpa.gnu.org/packages/). 46 | 47 | Any [legally significant](https://www.gnu.org/prep/maintain/html_node/Legally-Significant.html#Legally-Significant) contributions can only be accepted after the 48 | author has completed their paperwork. Please see [the request form](https://git.savannah.gnu.org/cgit/gnulib.git/tree/doc/Copyright/request-assign.future) if 49 | you want to proceed with the assignment. 50 | 51 | The copyright assignment isn't a big deal, it just says that the 52 | copyright for your submitted changes to Emacs belongs to the FSF. 53 | This assignment works for all projects related to Emacs. To obtain it 54 | you need to: 55 | * Send one email 56 | * Send one letter (if you live in the US, it's digital) 57 | * Wait for some time (recently it's less than a week) 58 | 59 | [1]: https://github.com/trevorpogue/topspace/issues 60 | [2]: http://gun.io/blog/how-to-github-fork-branch-and-pull-request 61 | [3]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html 62 | [4]: https://help.github.com/articles/using-pull-requests 63 | [5]: https://github.com/trevorpogue/topspace/blob/main/.github/workflows/ci.yml 64 | -------------------------------------------------------------------------------- /Cask: -------------------------------------------------------------------------------- 1 | (source gnu) 2 | (source melpa) 3 | 4 | (development 5 | (depends-on "undercover") 6 | (depends-on "buttercup") 7 | (depends-on "smooth-scrolling")) 8 | 9 | (package-file "topspace.el") 10 | -------------------------------------------------------------------------------- /HISTORY.md: -------------------------------------------------------------------------------- 1 | ## [v0.1.2](https://github.com/trevorpogue/topspace/tree/v0.1.2) (2022-03-01) 2 | 3 | [Full Changelog](https://github.com/trevorpogue/topspace/compare/v0.1.1...v0.1.2) 4 | 5 | **Fixed bugs:** 6 | * [#2](https://github.com/trevorpogue/topspace/pull/2): Make `recenter-top-bottom` act correctly when it moves point to bottom and top space is added to get there 7 | 8 | **Other changes:** 9 | 10 | * [2584138](https://github.com/trevorpogue/topspace/commit/25841387a5d0300ea49356b9781c357b84df20bd): Raise topspace-center-position default to a subjectively better position 11 | 12 | ## [v0.1.1](https://github.com/trevorpogue/topspace/tree/v0.1.1) (2022-02-22) 13 | 14 | [Full Changelog](https://github.com/trevorpogue/topspace/compare/v0.1.0...v0.1.1) 15 | 16 | **Fixed bugs:** 17 | 18 | * [4a69b2e](https://github.com/trevorpogue/topspace/commit/4a69b2eb741f8db9d69169a03a6724af0f2ec7ac): Allow recenter and recenter-top-bottom to be called interactively without an error 19 | * [4eb27ab](https://github.com/trevorpogue/topspace/commit/4eb27abaa182e856ba3f3c8e1e84fdd2e1f009af): Prevent top space from all suddenly disappearing when visual-line-mode is enabled and cursor scrolls bellow window-end when top space is present 20 | 21 | ## [v0.1.0](https://github.com/trevorpogue/topspace/tree/v0.1.0) (2022-02-19) 22 | 23 | [Full Changelog](https://github.com/trevorpogue/topspace/compare/79aa4e78d3f5c90fc9db46d597f1680c7900b52a...v0.1.0) 24 | 25 | **Implemented enhancements:** 26 | 27 | * [#1](https://github.com/trevorpogue/topspace/pull/1): Make mode work for any scrolling command by using add-advice with scroll-up, scroll-down, and recenter 28 | 29 | 30 | **Fixed bugs:** 31 | 32 | * [#1](https://github.com/trevorpogue/topspace/pull/1): Stabilize, clean up, and add performance optimizations to code to make it ready for submission to MELPA 33 | 34 | **Other changes:** 35 | 36 | * [e5b65ec](https://github.com/trevorpogue/topspace/commit/e5b65eccf92571163aa1b6bd738be22d8e0ad1a5): Change project name from vertical-center-mode to topspace 37 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /NEWS.md: -------------------------------------------------------------------------------- 1 | # History of user-visible changes 2 | 3 | ## [v0.3.1](https://github.com/trevorpogue/topspace/tree/v0.3.1) (2022-08-24) 4 | 5 | [Full Changelog](https://github.com/trevorpogue/topspace/compare/v0.3.0...v0.3.1) 6 | 7 | **Fixed bugs:** 8 | 9 | - Prevent line `1` indicator sometimes displaying too high in `linum-mode` [\#22](https://github.com/trevorpogue/topspace/pull/22) ([trevorpogue](https://github.com/trevorpogue)) 10 | 11 | ## [v0.3.0](https://github.com/trevorpogue/topspace/tree/v0.3.0) (2022-05-13) 12 | 13 | [Full Changelog](https://github.com/trevorpogue/topspace/compare/v0.2.1...v0.3.0) 14 | 15 | **Implemented enhancements:** 16 | 17 | - Add `topspace-set-height`, enhance `topspace-center-position` [\#19](https://github.com/trevorpogue/topspace/pull/19) ([trevorpogue](https://github.com/trevorpogue)) 18 | - Add `topspace-height` function for use by external packages [\#15](https://github.com/trevorpogue/topspace/pull/15) ([trevorpogue](https://github.com/trevorpogue)) 19 | - Add support for `smooth-scrolling` package [\#14](https://github.com/trevorpogue/topspace/pull/14) ([trevorpogue](https://github.com/trevorpogue)) 20 | 21 | **Fixed bugs:** 22 | 23 | - Fix unexpected top space height change when echo area height changes [\#18](https://github.com/trevorpogue/topspace/pull/18) ([trevorpogue](https://github.com/trevorpogue)) 24 | 25 | ## [v0.2.1](https://github.com/trevorpogue/topspace/tree/v0.2.1) (2022-04-15) 26 | 27 | [Full Changelog](https://github.com/trevorpogue/topspace/compare/v0.2.0...v0.2.1) 28 | 29 | **Fixed bugs:** 30 | 31 | - Prevent "Beginning of buffer" error message when scrolling above top [\#12](https://github.com/trevorpogue/topspace/pull/12) ([trevorpogue](https://github.com/trevorpogue)) 32 | - Fix inability to use scrolling commands interactively [\#11](https://github.com/trevorpogue/topspace/pull/11) ([trevorpogue](https://github.com/trevorpogue)) 33 | 34 | ## [v0.2.0](https://github.com/trevorpogue/topspace/tree/v0.2.0) (2022-04-12) 35 | 36 | [Full Changelog](https://github.com/trevorpogue/topspace/compare/v0.1.2...v0.2.0) 37 | 38 | **Implemented enhancements:** 39 | 40 | - Put topspace-empty-line-indicator inside left fringe [\#9](https://github.com/trevorpogue/topspace/pull/9) ([trevorpogue](https://github.com/trevorpogue)) 41 | - Add topspace-empty-line-indicator defcustom [\#8](https://github.com/trevorpogue/topspace/pull/8) ([trevorpogue](https://github.com/trevorpogue)) 42 | - Add `topspace-active`, improve `topspace-autocenter-buffers` [\#4](https://github.com/trevorpogue/topspace/pull/4) ([trevorpogue](https://github.com/trevorpogue)) 43 | 44 | **Fixed bugs:** 45 | 46 | - Support buffers with varying line heights [\#10](https://github.com/trevorpogue/topspace/pull/10) ([trevorpogue](https://github.com/trevorpogue)) 47 | - Fix bug where topspace-mode doesn't work locally [\#6](https://github.com/trevorpogue/topspace/pull/6) ([trevorpogue](https://github.com/trevorpogue)) 48 | 49 | ## [v0.1.2](https://github.com/trevorpogue/topspace/tree/v0.1.2) (2022-03-01) 50 | 51 | [Full Changelog](https://github.com/trevorpogue/topspace/compare/v0.1.1...v0.1.2) 52 | 53 | **Fixed bugs:** 54 | * [#2](https://github.com/trevorpogue/topspace/pull/2): Make `recenter-top-bottom` act correctly when it moves point to bottom and top space is added to get there 55 | 56 | **Other changes:** 57 | 58 | * [2584138](https://github.com/trevorpogue/topspace/commit/25841387a5d0300ea49356b9781c357b84df20bd): Raise topspace-center-position default to a subjectively better position 59 | 60 | ## [v0.1.1](https://github.com/trevorpogue/topspace/tree/v0.1.1) (2022-02-22) 61 | 62 | [Full Changelog](https://github.com/trevorpogue/topspace/compare/v0.1.0...v0.1.1) 63 | 64 | **Fixed bugs:** 65 | 66 | * [4a69b2e](https://github.com/trevorpogue/topspace/commit/4a69b2eb741f8db9d69169a03a6724af0f2ec7ac): Allow recenter and recenter-top-bottom to be called interactively without an error 67 | * [4eb27ab](https://github.com/trevorpogue/topspace/commit/4eb27abaa182e856ba3f3c8e1e84fdd2e1f009af): Prevent top space from all suddenly disappearing when visual-line-mode is enabled and cursor scrolls bellow window-end when top space is present 68 | 69 | ## [v0.1.0](https://github.com/trevorpogue/topspace/tree/v0.1.0) (2022-02-19) 70 | 71 | [Full Changelog](https://github.com/trevorpogue/topspace/compare/79aa4e78d3f5c90fc9db46d597f1680c7900b52a...v0.1.0) 72 | 73 | **Implemented enhancements:** 74 | 75 | * [#1](https://github.com/trevorpogue/topspace/pull/1): Make mode work for any scrolling command by using add-advice with scroll-up, scroll-down, and recenter 76 | 77 | 78 | **Fixed bugs:** 79 | 80 | * [#1](https://github.com/trevorpogue/topspace/pull/1): Stabilize, clean up, and add performance optimizations to code to make it ready for submission to MELPA 81 | 82 | **Other changes:** 83 | 84 | * [e5b65ec](https://github.com/trevorpogue/topspace/commit/e5b65eccf92571163aa1b6bd738be22d8e0ad1a5): Change project name from vertical-center-mode to topspace 85 | 86 | 87 | \* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)* 88 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

TopSpace

2 |

Scroll down & recenter top lines in Emacs.

3 | 4 | 5 | 6 |

7 | 8 | Coverage Status 9 | 10 | 11 | 12 | 13 |

14 | 15 |

16 | 17 |

18 | [ Installation | 19 | Usage | 20 | Customization | 21 | Extra functions | 22 | How it works ] 23 | 24 | TopSpace is an Emacs minor mode that lets you display a buffer's first line in the center of a window instead of just at the top. 25 | This is done by automatically drawing an upper margin/padding above line 1 26 | as you recenter and scroll it down. 27 | 28 | ### Features 29 | 30 | * **Easier on the eyes**: Recenter or scroll down top text to a more comfortable eye level for reading, especially when in full-screen or on a large monitor. 31 | * **Easy to use**: No new keybindings are required, keep using all your previous scrolling & recentering commands, except now you can also scroll down the first line. It also integrates seamlessly with [centered-cursor-mode][1] to keep the cursor centered all the way to the first line. 32 | 33 | # Installation 34 | Run the following command in Emacs 35 | 36 |      M-x `package-install` [RET] `topspace` [RET], 37 | 38 | then enable TopSpace locally with 39 | 40 |      M-x `topspace-mode`, 41 | 42 | or globally with 43 | 44 |      M-x `global-topspace-mode`. 45 | 46 | To enable `topspace-mode` globally on startup, add the following to your Emacs config 47 | ``` 48 | (global-topspace-mode 1) 49 | ``` 50 | # Usage 51 | ### Just enable and go 52 | No new keybindings are required, keep using all your previous scrolling & recentering commands, except now you can also scroll down the first line. 53 | 54 | # Customization 55 | ```elisp 56 | (defcustom topspace-active #'topspace-default-active 57 | "Determine when `topspace-mode' mode is active / has any effect on buffer. 58 | This is useful in particular when `global-topspace-mode' is enabled but you want 59 | `topspace-mode' to be inactive in certain buffers or in any specific 60 | circumstance. When inactive, `topspace-mode' will still technically be on, 61 | but will be effectively off and have no effect on the buffer. 62 | Note that if `topspace-active' returns non-nil but `topspace-mode' is off, 63 | `topspace-mode' will still be disabled. 64 | 65 | With the default value, topspace will only be inactive in child frames. 66 | 67 | If non-nil, then always be active. If nil, never be active. 68 | If set to a predicate function (function that returns a boolean value), 69 | then be active only when that function returns a non-nil value." 70 | :type '(choice (const :tag "always" t) 71 | (const :tag "never" nil) 72 | (function :tag "predicate function"))) 73 | 74 | (defcustom topspace-autocenter-buffers #'topspace-default-autocenter-buffers 75 | "Center small buffers with top space when first opened or window sizes change. 76 | This is done by automatically calling `topspace-recenter-buffer' 77 | and the positioning can be customized with `topspace-center-position'. 78 | Top space will not be added if the number of text lines in the buffer is larger 79 | than or close to the selected window's height, or if `window-start' is greater 80 | than 1. 81 | 82 | With the default value, buffers will not be centered if in a child frame 83 | or if the user has already scrolled or used `recenter' with buffer in the 84 | selected window. 85 | 86 | If non-nil, then always autocenter. If nil, never autocenter. 87 | If set to a predicate function (function that returns a boolean value), 88 | then do auto-centering only when that function returns a non-nil value." 89 | :group 'topspace 90 | :type '(choice (const :tag "always" t) 91 | (const :tag "never" nil) 92 | (function :tag "predicate function"))) 93 | 94 | (defcustom topspace-center-position 0.4 95 | "Target position when centering buffers. 96 | 97 | Used in `topspace-recenter-buffer' when called without an argument, or when 98 | opening/resizing buffers if `topspace-autocenter-buffers' returns non-nil. 99 | 100 | Can be set to a floating-point number, integer, or function that returns a 101 | floating-point number or integer. 102 | 103 | If a floating-point number, it represents the position to center buffers as a 104 | ratio of frame height, and can be a value from 0.0 to 1.0 where lower values 105 | center buffers higher up in the screen. 106 | 107 | If a positive or negative integer value, buffers will be centered by putting 108 | their center line at a distance of `topspace-center-position' lines away 109 | from the top of the selected window when positive, or from the bottom 110 | of the selected window when negative. 111 | The distance will be in units of lines with height `default-line-height', 112 | and the value should be less than the height of the window. 113 | 114 | If a function, the same rules above apply to the function's return value." 115 | :group 'topspace 116 | :type '(choice float integer 117 | (function :tag "float or integer function"))) 118 | 119 | (defcustom topspace-empty-line-indicator 120 | #'topspace-default-empty-line-indicator 121 | "Text that will appear in each empty topspace line above the top text line. 122 | Can be set to either a constant string or a function that returns a string. 123 | 124 | The conditions in which the indicator string is present are also customizable 125 | by setting `topspace-empty-line-indicator' to a function, where the function 126 | returns \"\" (an empty string) under any conditions in which you don't want 127 | the indicator string to be shown. 128 | 129 | By default it will show the empty-line bitmap in the left fringe 130 | if `indicate-empty-lines' is non-nil, otherwise nothing. 131 | This is done by adding a 'display property to the string (see 132 | `topspace-default-empty-line-indicator' for more details). 133 | The default bitmap is the one that the `empty-line' logical fringe indicator 134 | maps to in `fringe-indicator-alist'. 135 | 136 | You can alternatively show the string text in the body of each top space line by 137 | having `topspace-empty-line-indicator' return a string without the 'display 138 | property added. If you do this you may be interested in also changing the 139 | string's face like so: (propertize indicator-string 'face 'fringe)." 140 | :type '(choice 'string (function :tag "String function"))) 141 | 142 | (defcustom topspace-mode-line " T" 143 | "Mode line lighter for Topspace. 144 | The value of this variable is a mode line template as in 145 | `mode-line-format'. See Info Node `(elisp)Mode Line Format' for 146 | more information. Note that it should contain a _single_ mode 147 | line construct only. 148 | Set this variable to nil to disable the mode line completely." 149 | :group 'topspace 150 | :type 'sexp) 151 | 152 | (defvar topspace-keymap (make-sparse-keymap) 153 | "Keymap for Topspace commands. 154 | By default this is left empty for users to set with their own 155 | preferred bindings.") 156 | ``` 157 | 158 | # Extra functions 159 | 160 | ```elisp 161 | ;;;###autoload 162 | (defun topspace-height () 163 | "Return the top space height in lines for current buffer in selected window. 164 | The top space is the empty region in the buffer above the top text line. 165 | The return value is of type float, and is equivalent to 166 | the top space pixel height / `default-line-height'. 167 | 168 | If the height does not exist yet, zero will be returned if 169 | `topspace-autocenter-buffers' returns nil, otherwise a value that centers 170 | the buffer will be returned according to `topspace-center-position'. 171 | 172 | If the stored height is now invalid, it will first be corrected by 173 | `topspace--correct-height' before being returned. 174 | Valid top space line heights are: 175 | - never negative, 176 | - only positive when `window-start' equals 1, 177 | `topspace-active' returns non-nil, and `topspace-mode' is enabled, 178 | - not larger than `topspace--window-height' minus `topspace--context-lines'." 179 | ... 180 | 181 | ;;;###autoload 182 | (defun topspace-set-height (&optional total-lines) 183 | "Set and redraw the top space overlay to have a target height of TOTAL-LINES. 184 | This sets the top space height for the current buffer in the selected window. 185 | Integer or float values are accepted for TOTAL-LINES, and the value is 186 | considered to be in units of `default-line-height'. 187 | 188 | If argument TOTAL-LINES is not provided, the top space height will be set to 189 | the value returned by `topspace-height', which can be useful when redrawing a 190 | previously stored top space height in a window after a new buffer is 191 | displayed in it, or when first setting the height to an initial default value 192 | according to `topspace-height'. 193 | 194 | If TOTAL-LINES is invalid, it will be corrected by `topspace--correct-height'. 195 | Valid top space line heights are: 196 | - never negative, 197 | - only positive when `window-start' equals 1, 198 | `topspace-active' returns non-nil, and `topspace-mode' is enabled, 199 | - not larger than `topspace--window-height' minus `topspace--context-lines'." 200 | (interactive "P") 201 | ... 202 | 203 | ;;;###autoload 204 | (defun topspace-recenter-buffer (&optional position) 205 | "Add enough top space to center small buffers according to POSITION. 206 | POSITION defaults to `topspace-center-position'. 207 | Top space will not be added if the number of text lines in the buffer is larger 208 | than or close to the selected window's height, or if `window-start' is greater 209 | than 1. 210 | 211 | If POSITION is a float, it represents the position to center buffer as a ratio 212 | of frame height, and can be a value from 0.0 to 1.0 where lower values center 213 | the buffer higher up in the screen. 214 | 215 | If POSITION is a positive or negative integer value, buffer will be centered 216 | by putting its center line at a distance of `topspace-center-position' lines 217 | away from the top of the selected window when positive, or from the bottom 218 | of the selected window when negative. 219 | The distance will be in units of lines with height `default-line-height', 220 | and the value should be less than the height of the window. 221 | 222 | Top space will not be added if the number of text lines in the buffer is larger 223 | than or close to the selected window's height, or if `window-start' is greater 224 | than 1. 225 | 226 | Customize `topspace-center-position' to adjust the default centering position. 227 | Customize `topspace-autocenter-buffers' to run this command automatically 228 | after first opening buffers and after window sizes change." 229 | (interactive) 230 | ... 231 | 232 | ;;;###autoload 233 | (defun topspace-default-active () 234 | "Default function that `topspace-active' is set to. 235 | Return nil if the selected window is in a child-frame." 236 | ... 237 | 238 | ;;;###autoload 239 | (defun topspace-default-autocenter-buffers () 240 | "Default function that `topspace-autocenter-buffers' is set to. 241 | Return nil if the selected window is in a child-frame or user has scrolled 242 | buffer in selected window." 243 | ... 244 | 245 | ;;;###autoload 246 | (defun topspace-default-empty-line-indicator () 247 | "Default function that `topspace-empty-line-indicator' is set to. 248 | Put the empty-line bitmap in fringe if `indicate-empty-lines' is non-nil. 249 | This is done by adding a 'display property to the returned string. 250 | The bitmap used is the one that the `empty-line' logical fringe indicator 251 | maps to in `fringe-indicator-alist'." 252 | ... 253 | 254 | ;;;###autoload 255 | (defun topspace-buffer-was-scrolled-p () 256 | "Return t if current buffer has been scrolled in the selected window before. 257 | This is provided since it is used in `topspace-default-autocenter-buffers'. 258 | Scrolling is only recorded if topspace is active in the buffer at the time of 259 | scrolling." 260 | ... 261 | ``` 262 | 263 | # How it works 264 | 265 | The "upper margin" is created by drawing an [overlay](https://www.gnu.org/software/emacs/manual/html_node/elisp/Overlays.html) before 266 | window-start containing newline characters. As you scroll down the 267 | first line, more newline characters are added or removed accordingly. 268 | 269 | No new keybindings are required as topspace automatically works for 270 | any commands or subsequent function calls which use `scroll-up`, 271 | `scroll-down`, or `recenter` as the underlying primitives for 272 | scrolling. This includes all scrolling commands/functions available 273 | in Emacs as far as the author is aware. This is achieved by using 274 | `advice-add` with the `scroll-up`, `scroll-down`, and `recenter` 275 | commands so that custom topspace functions are called before or after 276 | each time any of these other commands are called (interactively or 277 | otherwise). 278 | 279 | Fill out the [satisfaction survey](https://www.supersurvey.com/QRMU65MKE) to help the author know what you would like improved or added. 280 | 281 | [1]: https://github.com/andre-r/centered-cursor-mode.el 282 | -------------------------------------------------------------------------------- /test/test-helper.el: -------------------------------------------------------------------------------- 1 | ;;; test-helper.el --- Helper for tests -*- lexical-binding: t; -*- 2 | 3 | ;; Copyright (C) 2022 Trevor Edwin Pogue 4 | 5 | ;; Author: Trevor Edwin Pogue 6 | 7 | ;;; Code: 8 | 9 | (when (require 'undercover nil t) 10 | (setq undercover-force-coverage t) 11 | (undercover "*.el" 12 | ;; (:report-file "coverage/.resultset.json") 13 | ;; (:report-format 'simplecov) 14 | ;; (:report-format 'text) 15 | )) 16 | 17 | (require 'smooth-scrolling) 18 | (require 'linum) 19 | (require 'topspace) 20 | 21 | ;;; test-helper.el ends here 22 | -------------------------------------------------------------------------------- /test/topspace-test.el: -------------------------------------------------------------------------------- 1 | ;;; test-topspace.el --- Main test file -*- lexical-binding: t -*- 2 | 3 | ;; Copyright (C) 2022 Trevor Edwin Pogue 4 | 5 | ;; Author: Trevor Edwin Pogue 6 | 7 | ;;; Code: 8 | 9 | (setq topspace--log-target '(file . "~/topspace/topspace.log")) 10 | (setq topspace--start-time (float-time)) 11 | (setq topspace--scroll-down-scale-factor 0) 12 | 13 | (defun topspace--log (message) 14 | "Log MESSAGE." 15 | (when topspace--log-target 16 | (let ((log-line (format "%06d %s\n" 17 | (round (- (* 1000 (float-time)) 18 | (* 1000 topspace--start-time))) 19 | message)) 20 | (target-type (car topspace--log-target)) 21 | (target-name (cdr topspace--log-target))) 22 | (pcase target-type 23 | ('buffer 24 | (with-current-buffer (get-buffer-create target-name) 25 | (goto-char (point-max)) 26 | (insert log-line))) 27 | ('file 28 | (let ((save-silently t)) 29 | (append-to-file log-line nil target-name))) 30 | (_ 31 | (error "Unrecognized log target type: %S" target-type)))))) 32 | 33 | (defmacro topspace--cmds (&rest cmds) 34 | "Run CMDS with command hooks." 35 | (let ((result '(progn))) 36 | (dolist (cmd cmds) 37 | (setq result 38 | (append result 39 | `((run-hooks 'pre-command-hook) 40 | (eval ',cmd) 41 | (run-hooks 'post-command-hook) 42 | )))) 43 | result)) 44 | 45 | (describe 46 | "topspace" 47 | :var (prev-height) 48 | 49 | (before-all 50 | (setq topspace-center-position 0.42) 51 | (topspace--cmds (set-frame-size (selected-frame) 90 24)) 52 | (switch-to-buffer (find-file-noselect "./topspace.el" t)) 53 | (global-topspace-mode)) 54 | 55 | (before-each (switch-to-buffer "topspace.el")) 56 | 57 | (it "reduces top space height before cursor can move below window-end" 58 | (goto-char 1) 59 | (topspace-set-height 0) 60 | (topspace--cmds 61 | (scroll-down) 62 | (scroll-up) 63 | (scroll-down) 64 | ) 65 | (setq prev-height (topspace-height)) 66 | (topspace--cmds 67 | (next-line)) 68 | (expect (topspace-height) :to-equal (1- prev-height)) 69 | (topspace--cmds (next-line 4)) 70 | (expect (topspace-height) :to-equal (- prev-height 5)) 71 | (topspace--cmds (scroll-down 2))) 72 | 73 | (it "moves cursor up before cursor is scrolled below window-end" 74 | (topspace--cmds (scroll-down-line)) 75 | (expect (topspace-height) :to-equal (- prev-height 2)) 76 | (topspace--cmds 77 | (scroll-down-line) 78 | (scroll-down-line)) 79 | (expect (topspace-height) :to-equal prev-height) 80 | (topspace--cmds (scroll-up-line)) 81 | (expect (topspace-height) :to-equal (1- prev-height))) 82 | 83 | (describe 84 | "topspace--after-scroll" 85 | (it "is needed when first scrolling above the top line" 86 | (goto-char 1) 87 | (topspace-set-height 0) 88 | (scroll-up-line) 89 | (scroll-down 2) 90 | (goto-char 1) 91 | (topspace-set-height 0) 92 | (scroll-up-line) 93 | (scroll-down 2) 94 | (expect (round (topspace-height)) :to-equal 1) 95 | )) 96 | 97 | (describe 98 | "topspace--window-configuration-change" 99 | 100 | (it "autocenters buffer when window size changes" 101 | (switch-to-buffer "*scratch*") 102 | (run-hooks 'window-configuration-change-hook) 103 | (expect (round (* (topspace-height) 10)) :to-equal 78) 104 | (topspace--cmds (set-frame-size (selected-frame) 90 22)) 105 | (run-hooks 'window-configuration-change-hook) 106 | (expect (round (* (topspace-height) 10)) :to-equal 70) 107 | (topspace--cmds (set-frame-size (selected-frame) 90 24))) 108 | 109 | (it "will redraw topspace even if window height didn't change 110 | in case topspace-autocenter-buffers changed return value" 111 | (spy-on 'topspace-set-height) 112 | (topspace--window-configuration-change) 113 | (expect 'topspace-set-height :to-have-been-called))) 114 | 115 | (describe 116 | "topspace-mode" 117 | (it "can be enabled and disabled locally" 118 | (topspace-mode -1) 119 | (expect topspace-mode :to-equal nil) 120 | (scroll-up-line) 121 | (topspace-set-height 1) 122 | (expect (topspace-height) :to-equal 0.0) 123 | (ignore-errors (scroll-down-line)) 124 | (topspace-mode 1) 125 | (expect topspace-mode :to-equal t) 126 | (switch-to-buffer "*scratch*") 127 | (topspace-mode -1) 128 | (topspace-recenter-buffer) 129 | (expect (topspace-height) :to-equal 0.0) 130 | (topspace-mode 1))) 131 | 132 | (describe 133 | "topspace--center-line" 134 | (it "has an optional argument that takes the value `topspace-center-position' 135 | by default" 136 | (expect (topspace--center-line) :to-equal 137 | (topspace--center-line topspace-center-position)))) 138 | 139 | (describe 140 | "topspace--increase-height" 141 | (it "increases top space height" 142 | (goto-char 1) 143 | (recenter) 144 | (setq prev-height (topspace-height)) 145 | (topspace--increase-height 1) 146 | (expect (topspace-height) :to-equal (1+ prev-height)))) 147 | 148 | (describe 149 | "topspace--after-recenter" 150 | (it "adds top space if recentering near top of buffer" 151 | (goto-char 1) 152 | (recenter) 153 | (expect (round (topspace-height)) :to-equal (/ (window-height) 2)) 154 | (recenter -1) 155 | (expect (round (topspace-height)) :to-equal (- (window-height) 2)))) 156 | 157 | (describe 158 | "topspace--previous-line" 159 | (it "is to be used like previous-line but non-interactively" 160 | (goto-char 1) 161 | (next-line) 162 | (topspace--previous-line) 163 | (expect (line-number-at-pos) :to-equal 1) 164 | (should-error (topspace--previous-line)))) 165 | 166 | (describe 167 | "topspace--smooth-scroll-lines-above-point" 168 | (it "allows smooth-scrolling package to work with topspace" 169 | :to-equal (smooth-scroll-lines-above-point) 170 | (progn (goto-char 1) 171 | (topspace-set-height 0) 172 | (goto-line smooth-scroll-margin) 173 | (set-window-start (selected-window) (point)) 174 | (scroll-down smooth-scroll-margin) 175 | (setq smooth-scrolling-mode nil) 176 | (call-interactively 'smooth-scrolling-mode)) 177 | (previous-line) 178 | (previous-line) 179 | (expect (round (topspace-height)) :to-equal 2) 180 | (setq smooth-scrolling-mode nil))) 181 | 182 | (describe 183 | "topspace-default-empty-line-indicator" 184 | (it "can return a string with an indicator in left-fringe" 185 | (setq indicate-empty-lines t) 186 | (add-to-list 'fringe-indicator-alist '(up . up-arrow)) 187 | (let ((bitmap (catch 'tag (dolist (x fringe-indicator-alist) 188 | (when (eq (car x) 'empty-line) 189 | (throw 'tag (cdr x))))))) 190 | (expect (topspace-default-empty-line-indicator) :to-equal 191 | (propertize " " 'display (list `left-fringe bitmap 192 | `fringe)))))) 193 | (describe 194 | "topspace--count-lines" 195 | ;; TODO: figure out how to test cask on a graphical emacs frame with display 196 | ;; (it "can count lines if window-absolute-pixel-position returns non-nil" 197 | ;; (expect (display-graphic-p) :to-equal nil) 198 | ;; (make-frame-on-display ":0") 199 | ;; (topspace--log (frame-list)) 200 | ;; (sit-for 1) 201 | ;; (with-selected-window 202 | ;; ;; (switch-to-buffer "topspace.el") 203 | ;; (frame-selected-window (car (frames-on-display-list))) 204 | ;; (expect (round (topspace--count-lines (point-min) (point-max))) 205 | ;; :to-equal 206 | ;; (line-number-at-pos (point-max))))) 207 | 208 | (it "can count lines'" 209 | (set-window-start (selected-window) 300) 210 | (expect (round (topspace--count-lines (window-start) 211 | (topspace--window-end))) 212 | :to-equal (count-screen-lines (window-start) 213 | (topspace--window-end))) 214 | (set-window-start (selected-window) 1)) 215 | 216 | (it "can count lines if start is larger than end" 217 | (set-window-start (selected-window) 300) 218 | (expect (round (topspace--count-lines 401 201)) 219 | :to-equal 4) 220 | (expect (round (topspace--count-lines 201 401)) 221 | :to-equal 4) 222 | (set-window-start (selected-window) 1)) 223 | 224 | (it "can count lines if window-absolute-pixel-position returns nil" 225 | (expect (round (round (topspace--count-lines 201 401))) 226 | :to-equal 227 | 4))) 228 | 229 | (describe 230 | "topspace--correct-height" 231 | (it "fixes topspace height when larger than max valid value" 232 | (let ((max-height 233 | (- (window-text-height) topspace--context-lines))) 234 | (expect (topspace--correct-height (1+ max-height)) 235 | :to-equal max-height)))) 236 | 237 | (describe 238 | "topspace-height" 239 | (it "by default returns 0 for new buffer when topspace-autocenter-buffers 240 | returns nil" 241 | (let ((prev-autocenter-val topspace-autocenter-buffers)) 242 | (setq topspace--heights '()) 243 | (setq topspace-autocenter-buffers nil) 244 | (expect (topspace-height) :to-equal 0.0) 245 | (setq topspace-autocenter-buffers prev-autocenter-val)))) 246 | 247 | (describe 248 | "topspace--current-line-plus-topspace" 249 | (it "can accept an arg or no args" 250 | (expect (topspace--current-line-plus-topspace) 251 | :to-equal (topspace--current-line-plus-topspace 252 | (topspace-height))))) 253 | 254 | (describe 255 | "topspace-center-position" 256 | (it "can be a float value or function, in which case 257 | its return value represents the position to center buffers as a ratio of 258 | frame height, and can be a value from 0 to 1 where lower values center 259 | buffers higher up in the screen." 260 | (setq topspace--prev-center-position topspace-center-position) 261 | (setq topspace-center-position 0.5) 262 | (switch-to-buffer "*scratch*") 263 | (topspace-recenter-buffer) 264 | (expect (topspace-height) :to-equal 265 | (- (* (topspace--frame-height) 266 | (topspace--eval-choice topspace-center-position)) 267 | (window-top-line))) 268 | (defun topspace--center-position-test () 0.5) 269 | (setq topspace-center-position #'topspace--center-position-test) 270 | (topspace-recenter-buffer) 271 | (expect (topspace-height) :to-equal 272 | (- (* (topspace--frame-height) 273 | (topspace--eval-choice topspace-center-position)) 274 | (window-top-line))) 275 | (setq topspace-center-position topspace--prev-center-position)) 276 | 277 | (it "can be an integer value or function, in which case: 278 | 279 | If a positive integer value, buffers will be centered putting their center 280 | line at a distance of `topspace-center-position' from the top of the 281 | selected window. 282 | 283 | If a negative integer value, buffers will be centered putting their center 284 | line at line at a distance of `topspace-center-position' away from 285 | the bottom of the selected window. 286 | (ARG should be less than the height of the window.)" 287 | (setq topspace--prev-center-position topspace-center-position) 288 | (setq topspace-center-position 4) 289 | (switch-to-buffer "*scratch*") 290 | ;; (expect (topspace-height) :to-equal (/ (frame-text-lines) 2)) 291 | (topspace-recenter-buffer) 292 | (expect (topspace-height) :to-equal 4.0) 293 | (defun topspace--center-position-test () 4) 294 | (setq topspace-center-position #'topspace--center-position-test) 295 | (topspace-recenter-buffer) 296 | (expect (topspace-height) :to-equal 4.0) 297 | (setq topspace-center-position -4) 298 | (topspace-recenter-buffer) 299 | (expect (topspace-height) :to-equal (float (- (window-text-height) 300 | topspace--context-lines))) 301 | (setq topspace-center-position topspace--prev-center-position)) 302 | ) 303 | ) 304 | 305 | ;;; test-topspace.el ends here 306 | -------------------------------------------------------------------------------- /topspace.el: -------------------------------------------------------------------------------- 1 | ;;; topspace.el --- Recenter line 1 with scrollable upper margin/padding -*- lexical-binding: t -*- 2 | 3 | ;; Copyright (C) 2021-2022 Free Software Foundation, Inc. 4 | 5 | ;; Author: Trevor Edwin Pogue 6 | ;; Maintainer: Trevor Edwin Pogue 7 | ;; URL: https://github.com/trevorpogue/topspace 8 | ;; Keywords: convenience, scrolling, center, cursor, margin, padding 9 | ;; Version: 0.3.1 10 | ;; Package-Requires: ((emacs "25.1")) 11 | 12 | ;; This file is part of GNU Emacs. 13 | 14 | ;; GNU Emacs is free software: you can redistribute it and/or modify 15 | ;; it under the terms of the GNU General Public License as published by 16 | ;; the Free Software Foundation, either version 3 of the License, or 17 | ;; (at your option) any later version. 18 | 19 | ;; GNU Emacs is distributed in the hope that it will be useful, 20 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 | ;; GNU General Public License for more details. 23 | 24 | ;; You should have received a copy of the GNU General Public License 25 | ;; along with GNU Emacs. If not, see . 26 | 27 | ;;; Commentary: 28 | 29 | ;; TopSpace lets you display a buffer's first line in the center of a window 30 | ;; instead of just at the top. 31 | ;; This is done by automatically drawing an upper margin/padding above line 1 32 | ;; as you recenter and scroll it down. 33 | 34 | ;; See https://github.com/trevorpogue/topspace for a GIF demo & documentation. 35 | 36 | ;; Features: 37 | 38 | ;; - Easier on the eyes: Recenter or scroll down top text to a more 39 | ;; comfortable eye level for reading, especially when in full-screen 40 | ;; or on a large monitor. 41 | 42 | ;; - Easy to use: No new keybindings are required, keep using all 43 | ;; your previous scrolling & recentering commands, except now you 44 | ;; can also scroll down the first line. It also integrates 45 | ;; seamlessly with `centered-cursor-mode' to keep the cursor 46 | ;; centered all the way to the first line. 47 | 48 | ;;; Code: 49 | 50 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 51 | ;;; Private variables 52 | 53 | (defvar-local topspace--heights '() 54 | "Stores top space heights of each window that buffer has been selected in.") 55 | 56 | (defvar-local topspace--buffer-was-scrolled '() 57 | "Stores if user has scrolled buffer in selected window before. 58 | Only recorded if topspace is active in the buffer at the time of scrolling.") 59 | 60 | (defvar-local topspace--previous-window-heights '() 61 | "Stores the window heights of each window that buffer has been selected in.") 62 | 63 | (defvar-local topspace--window-start-before-scroll 2 64 | "Helps to identify if more top space must be drawn after scrolling up.") 65 | 66 | (defvar-local topspace--total-lines-scrolling 0 67 | "Stores the total lines that the user is scrolling until scroll is complete.") 68 | 69 | (defvar-local topspace--pre-command-point 1 70 | "Used for performance improvement by abandoning extra calculations. 71 | In the post command hook, this determines if point moved further than the 72 | window height, in which case there is no point checking if the top space 73 | should be reduced in size or not. It also determines the direction of 74 | movement that the user is moving point in since some `post-command-hook' 75 | operations are only needed when moving downward.") 76 | 77 | (defvar-local topspace--pre-command-window-start 2 78 | "Used for performance improvement by abandoning extra calculations. 79 | In the post command hook, this determines if any top space was present 80 | before the command, otherwise there is no point checking if the top 81 | space should be reduced in size or not.") 82 | 83 | (defvar-local topspace--got-first-window-configuration-change nil 84 | "Displaying top space before the first window config change can cause errors. 85 | This flag signals to wait until then to display top space.") 86 | 87 | (defvar topspace--advice-added nil 88 | "Keeps track of if `advice-add' has been done already.") 89 | 90 | (defvar topspace--scroll-down-scale-factor 1 91 | "For eliminating an error when testing in non-interactive batch mode. 92 | An error occurs in this mode any time `scroll-down' is passed a 93 | non-zero value, which halts tests and makes testing many topspace features 94 | impossible. So this variable is set to zero when testing in this mode.") 95 | 96 | (defvar topspace--context-lines 1 97 | "Determines how many lines away from `window-end' the cursor can get. 98 | This is relevant when scrolling in such a way that the cursor tries to 99 | move past `window-end'.") 100 | 101 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 102 | ;;; Customization 103 | 104 | (defgroup topspace nil 105 | "Scroll down & recenter top lines / get upper margins/padding." 106 | :group 'scrolling 107 | :group 'convenience 108 | :link '(emacs-library-link :tag "Source Lisp File" "topspace.el") 109 | :link '(url-link "https://github.com/trevorpogue/topspace") 110 | :link '(emacs-commentary-link :tag "Commentary" "topspace")) 111 | 112 | (defcustom topspace-active #'topspace-default-active 113 | "Determine when `topspace-mode' mode is active / has any effect on buffer. 114 | This is useful in particular when `global-topspace-mode' is enabled but you want 115 | `topspace-mode' to be inactive in certain buffers or in any specific 116 | circumstance. When inactive, `topspace-mode' will still technically be on, 117 | but will be effectively off and have no effect on the buffer. 118 | Note that if `topspace-active' returns non-nil but `topspace-mode' is off, 119 | `topspace-mode' will still be disabled. 120 | 121 | With the default value, topspace will only be inactive in child frames. 122 | 123 | If non-nil, then always be active. If nil, never be active. 124 | If set to a predicate function (function that returns a boolean value), 125 | then be active only when that function returns a non-nil value." 126 | :type '(choice (const :tag "always" t) 127 | (const :tag "never" nil) 128 | (function :tag "predicate function"))) 129 | 130 | (defcustom topspace-autocenter-buffers #'topspace-default-autocenter-buffers 131 | "Center small buffers with top space when first opened or window sizes change. 132 | This is done by automatically calling `topspace-recenter-buffer' 133 | and the positioning can be customized with `topspace-center-position'. 134 | Top space will not be added if the number of text lines in the buffer is larger 135 | than or close to the selected window's height, or if `window-start' is greater 136 | than 1. 137 | 138 | With the default value, buffers will not be centered if in a child frame 139 | or if the user has already scrolled or used `recenter' with buffer in the 140 | selected window. 141 | 142 | If non-nil, then always autocenter. If nil, never autocenter. 143 | If set to a predicate function (function that returns a boolean value), 144 | then do auto-centering only when that function returns a non-nil value." 145 | :group 'topspace 146 | :type '(choice (const :tag "always" t) 147 | (const :tag "never" nil) 148 | (function :tag "predicate function"))) 149 | 150 | (defcustom topspace-center-position 0.4 151 | "Target position when centering buffers. 152 | 153 | Used in `topspace-recenter-buffer' when called without an argument, or when 154 | opening/resizing buffers if `topspace-autocenter-buffers' returns non-nil. 155 | 156 | Can be set to a floating-point number, integer, or function that returns a 157 | floating-point number or integer. 158 | 159 | If a floating-point number, it represents the position to center buffers as a 160 | ratio of frame height, and can be a value from 0.0 to 1.0 where lower values 161 | center buffers higher up in the screen. 162 | 163 | If a positive or negative integer value, buffers will be centered by putting 164 | their center line at a distance of `topspace-center-position' lines away 165 | from the top of the selected window when positive, or from the bottom 166 | of the selected window when negative. 167 | The distance will be in units of lines with height `default-line-height', 168 | and the value should be less than the height of the window. 169 | 170 | If a function, the same rules above apply to the function's return value." 171 | :group 'topspace 172 | :type '(choice float integer 173 | (function :tag "floating-point number or integer function"))) 174 | 175 | (defcustom topspace-empty-line-indicator 176 | #'topspace-default-empty-line-indicator 177 | "Text that will appear in each empty topspace line above the top text line. 178 | Can be set to either a constant string or a function that returns a string. 179 | 180 | The conditions in which the indicator string is present are also customizable 181 | by setting `topspace-empty-line-indicator' to a function, where the function 182 | returns \"\" (an empty string) under any conditions in which you don't want 183 | the indicator string to be shown. 184 | 185 | By default it will show the empty-line bitmap in the left fringe 186 | if `indicate-empty-lines' is non-nil, otherwise nothing. 187 | This is done by adding a 'display property to the string (see 188 | `topspace-default-empty-line-indicator' for more details). 189 | The default bitmap is the one that the `empty-line' logical fringe indicator 190 | maps to in `fringe-indicator-alist'. 191 | 192 | You can alternatively show the string text in the body of each top space line by 193 | having `topspace-empty-line-indicator' return a string without the 'display 194 | property added. If you do this you may be interested in also changing the 195 | string's face like so: (propertize indicator-string 'face 'fringe)." 196 | :type '(choice 'string (function :tag "String function"))) 197 | 198 | (defcustom topspace-mode-line " T" 199 | "Mode line lighter for Topspace. 200 | The value of this variable is a mode line template as in 201 | `mode-line-format'. See Info Node `(elisp)Mode Line Format' for 202 | more information. Note that it should contain a _single_ mode 203 | line construct only. 204 | Set this variable to nil to disable the mode line completely." 205 | :group 'topspace 206 | :type 'sexp) 207 | 208 | (defvar topspace-keymap (make-sparse-keymap) 209 | "Keymap for Topspace commands. 210 | By default this is left empty for users to set with their own 211 | preferred bindings.") 212 | 213 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 214 | ;;; User functions 215 | 216 | ;;;###autoload 217 | (defun topspace-height () 218 | "Return the top space height in lines for current buffer in selected window. 219 | The top space is the empty region in the buffer above the top text line. 220 | The return value is a floating-point number, and is equivalent to 221 | the top space pixel height / `default-line-height'. 222 | 223 | If the height does not exist yet, zero will be returned if 224 | `topspace-autocenter-buffers' returns nil, otherwise a value that centers 225 | the buffer will be returned according to `topspace-center-position'. 226 | 227 | If the stored height is now invalid, it will first be corrected by 228 | `topspace--correct-height' before being returned. 229 | Valid top space line heights are: 230 | - never negative, 231 | - only positive when `window-start' equals 1, 232 | `topspace-active' returns non-nil, and `topspace-mode' is enabled, 233 | - not larger than `window-text-height' minus `topspace--context-lines'." 234 | (let ((height) (window (selected-window))) 235 | ;; First try returning previously stored top space height 236 | (setq height (alist-get window topspace--heights)) 237 | (unless height 238 | ;; If it has never been created before then get the default value 239 | (setq height (if (topspace--eval-choice topspace-autocenter-buffers) 240 | (topspace--height-to-recenter-buffer) 0.0))) 241 | ;; Correct, store, and return the new value 242 | (topspace--set-height height))) 243 | 244 | ;;;###autoload 245 | (defun topspace-set-height (&optional total-lines) 246 | "Set and redraw the top space overlay to have a target height of TOTAL-LINES. 247 | This sets the top space height for the current buffer in the selected window. 248 | Integer or floating-point numbers are accepted for TOTAL-LINES, and the value is 249 | considered to be in units of `default-line-height'. 250 | 251 | If argument TOTAL-LINES is not provided, the top space height will be set to 252 | the value returned by `topspace-height', which can be useful when redrawing a 253 | previously stored top space height in a window after a new buffer is 254 | displayed in it, or when first setting the height to an initial default value 255 | according to `topspace-height'. 256 | 257 | If TOTAL-LINES is invalid, it will be corrected by `topspace--correct-height'. 258 | Valid top space line heights are: 259 | - never negative, 260 | - only positive when `window-start' equals 1, 261 | `topspace-active' returns non-nil, and `topspace-mode' is enabled, 262 | - not larger than `window-text-height' minus `topspace--context-lines'." 263 | (interactive "P") 264 | (let ((old-height) (window (selected-window))) 265 | ;; Get the previous top space height 266 | (unless old-height (setq old-height (topspace-height))) 267 | ;; Get the default value if TOTAL-LINES arg not provided 268 | (unless total-lines (setq total-lines old-height)) 269 | ;; Update or correct the stored top space height to new value 270 | (setq total-lines (topspace--correct-height 271 | (topspace--set-height total-lines))) 272 | (when (and (> total-lines 0) (> total-lines old-height)) 273 | ;; If top space height is increasing, make sure it doesn't push the 274 | ;; cursor off the screen 275 | (let ((lines-past-max (topspace--total-lines-past-max total-lines))) 276 | (when (> lines-past-max 0) 277 | (topspace--previous-line (ceiling lines-past-max))))) 278 | (let ((topspace (make-overlay 1 1))) 279 | ;; Redraw top space with the new height by drawing a new overlay and 280 | ;; erasing any previously drawn overlays for current buffer in 281 | ;; selected window 282 | (remove-overlays 1 1 'topspace--remove-from-window-tag window) 283 | (overlay-put topspace 'window window) 284 | (overlay-put topspace 'topspace--remove-from-window-tag window) 285 | (overlay-put topspace 'topspace--remove-from-buffer-tag t) 286 | (overlay-put topspace 'before-string (topspace--text total-lines))) 287 | ;; Return the new height 288 | total-lines)) 289 | 290 | ;;;###autoload 291 | (defun topspace-recenter-buffer (&optional position) 292 | "Add enough top space to center small buffers according to POSITION. 293 | POSITION defaults to `topspace-center-position'. 294 | Top space will not be added if the number of text lines in the buffer is larger 295 | than or close to the selected window's height, or if `window-start' is greater 296 | than 1. 297 | 298 | If POSITION is a floating-point, it represents the position to center buffer as 299 | a ratio of frame height, and can be a value from 0.0 to 1.0 where lower values 300 | center the buffer higher up in the screen. 301 | 302 | If POSITION is a positive or negative integer value, buffer will be centered 303 | by putting its center line at a distance of `topspace-center-position' lines 304 | away from the top of the selected window when positive, or from the bottom 305 | of the selected window when negative. 306 | The distance will be in units of lines with height `default-line-height', 307 | and the value should be less than the height of the window. 308 | 309 | Top space will not be added if the number of text lines in the buffer is larger 310 | than or close to the selected window's height, or if `window-start' is greater 311 | than 1. 312 | 313 | Customize `topspace-center-position' to adjust the default centering position. 314 | Customize `topspace-autocenter-buffers' to run this command automatically 315 | after first opening buffers and after window sizes change." 316 | (interactive) 317 | (cond 318 | ((not (topspace--enabled)) (topspace-set-height 0.0)) 319 | (t (topspace-set-height (topspace--height-to-recenter-buffer position))))) 320 | 321 | ;;;###autoload 322 | (defun topspace-default-active () 323 | "Default function that `topspace-active' is set to. 324 | Return nil if the selected window is in a child-frame." 325 | (or ;; frame-parent is only provided in Emacs 26.1, so first check 326 | ;; if fhat function exists. 327 | (not (fboundp 'frame-parent)) 328 | (not (frame-parent)))) 329 | 330 | ;;;###autoload 331 | (defun topspace-default-autocenter-buffers () 332 | "Default function that `topspace-autocenter-buffers' is set to. 333 | Return nil if the selected window is in a child-frame or user has scrolled 334 | buffer in selected window." 335 | (and (not (topspace-buffer-was-scrolled-p)) 336 | (or ;; frame-parent is only provided in Emacs 26.1, so first check 337 | ;; if fhat function exists. 338 | (not (fboundp 'frame-parent)) 339 | (not (frame-parent))))) 340 | 341 | ;;;###autoload 342 | (defun topspace-default-empty-line-indicator () 343 | "Default function that `topspace-empty-line-indicator' is set to. 344 | Put the empty-line bitmap in fringe if `indicate-empty-lines' is non-nil. 345 | This is done by adding a 'display property to the returned string. 346 | The bitmap used is the one that the `empty-line' logical fringe indicator 347 | maps to in `fringe-indicator-alist'." 348 | (if indicate-empty-lines 349 | (let ((bitmap 350 | (catch 'tag 351 | (dolist (x fringe-indicator-alist) 352 | (when (eq (car x) 'empty-line) (throw 'tag (cdr x))))))) 353 | (propertize " " 'display (list `left-fringe bitmap `fringe))) 354 | "")) 355 | 356 | ;;;###autoload 357 | (defun topspace-buffer-was-scrolled-p () 358 | "Return t if current buffer has been scrolled in the selected window before. 359 | This is provided since it is used in `topspace-default-autocenter-buffers'. 360 | Scrolling is only recorded if topspace is active in the buffer at the time of 361 | scrolling." 362 | (alist-get (selected-window) topspace--buffer-was-scrolled)) 363 | 364 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 365 | ;;; Advice for `scroll-up', `scroll-down', and `recenter' 366 | 367 | (defun topspace--scroll (total-lines) 368 | "Run before `scroll-up'/`scroll-down' for updating top space before scrolling. 369 | TOTAL-LINES is used in the same way as in `scroll-down'." 370 | (setf (alist-get (selected-window) topspace--buffer-was-scrolled) t) 371 | (let ((old-topspace-height (topspace-height)) 372 | (new-topspace-height)) 373 | (setq new-topspace-height (topspace--correct-height 374 | (+ old-topspace-height total-lines))) 375 | (setq topspace--window-start-before-scroll (window-start)) 376 | (topspace-set-height new-topspace-height) 377 | (setq total-lines 378 | (- total-lines (- new-topspace-height old-topspace-height))) 379 | (round total-lines))) 380 | 381 | (defun topspace--filter-args-scroll-down (&optional total-lines) 382 | "Run before `scroll-down' for scrolling above the top line. 383 | TOTAL-LINES is used in the same way as in `scroll-down'." 384 | (cond 385 | ((not (topspace--enabled)) (topspace-set-height 0.0) total-lines) 386 | (t 387 | (setq total-lines (car total-lines)) 388 | (setq total-lines (or total-lines (- (window-text-height) 389 | next-screen-context-lines))) 390 | (setq topspace--total-lines-scrolling total-lines) 391 | (list (* topspace--scroll-down-scale-factor 392 | (topspace--scroll total-lines)))))) 393 | 394 | (defun topspace--filter-args-scroll-up (&optional total-lines) 395 | "Run before `scroll-up' for scrolling above the top line. 396 | TOTAL-LINES is used in the same way as in `scroll-up'." 397 | (cond 398 | ((not (topspace--enabled)) (topspace-set-height 0.0) total-lines) 399 | (t 400 | (setq total-lines (car total-lines)) 401 | (setq total-lines (* (or total-lines (- (window-text-height) 402 | next-screen-context-lines)) -1)) 403 | (setq topspace--total-lines-scrolling total-lines) 404 | (list (* (topspace--scroll total-lines) -1))))) 405 | 406 | (defun topspace--after-scroll (&optional total-lines) 407 | "Run after `scroll-up'/`scroll-down' for scrolling above the top line. 408 | TOTAL-LINES is used in the same way as in `scroll-down'. 409 | This is needed when scrolling down (moving buffer text lower in the screen) 410 | and no top space was present before scrolling but it should be after scrolling. 411 | The reason this is needed is because `topspace-set-height' only draws the 412 | overlay when `window-start` equals 1, which can only be true after the scroll 413 | command is run in the described case above." 414 | (cond 415 | ((not (topspace--enabled))) 416 | (t 417 | (setq total-lines topspace--total-lines-scrolling) 418 | (when (and (> topspace--window-start-before-scroll 1) (= (window-start) 1)) 419 | (let ((lines-already-scrolled (topspace--count-lines 420 | 1 topspace--window-start-before-scroll))) 421 | (setq total-lines (abs total-lines)) 422 | (set-window-start (selected-window) 1) 423 | (topspace-set-height (- total-lines lines-already-scrolled))) 424 | (when (and (bound-and-true-p linum-mode) (fboundp 'linum-update-window)) 425 | (linum-update-window (selected-window))))))) 426 | 427 | (defun topspace--after-recenter (&optional line-offset redisplay) 428 | "Recenter near the top of buffers by adding top space appropriately. 429 | LINE-OFFSET and REDISPLAY are used in the same way as in `recenter'." 430 | ;; redisplay is unused but needed since this function 431 | ;; must take the same arguments as `recenter' 432 | redisplay ; remove flycheck warning for unused argument (see above) 433 | (cond 434 | ((not (topspace--enabled))) 435 | (t 436 | (setf (alist-get (selected-window) topspace--buffer-was-scrolled) t) 437 | (when (= (window-start) 1) 438 | (setq line-offset (topspace--calculate-recenter-line-offset line-offset)) 439 | (topspace-set-height (- line-offset (topspace--count-lines 440 | (window-start) 441 | (point)))))))) 442 | 443 | (defun topspace--smooth-scroll-lines-above-point (&rest args) 444 | "Add support for `smooth-scroll-mode', ignore ARGS. 445 | ARGS are needed for compatibility with `advice-add'." 446 | ;; remove flycheck warnings by using R and checking smooth-scroll functions 447 | args 448 | (when (and (fboundp 'smooth-scroll-count-lines) 449 | (fboundp 'smooth-scroll-line-beginning-position)) 450 | (+ (topspace-height) 451 | (smooth-scroll-count-lines 452 | (window-start) (smooth-scroll-line-beginning-position))))) 453 | 454 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 455 | ;;; Top space line height calculation 456 | 457 | (defun topspace--set-height (height) 458 | "Set the stored top space line height for the selected window to HEIGHT. 459 | Will only set to HEIGHT if HEIGHT is a valid value as per 460 | `topspace--correct-height'. This only sets the underlying stored value for 461 | top space height, and it does not redraw the top space." 462 | (setq height (topspace--correct-height height)) 463 | (setf (alist-get (selected-window) topspace--heights) height) 464 | height) 465 | 466 | (defun topspace--correct-height (height) 467 | "Return HEIGHT if a valid top space line height, else a valid value. 468 | Valid top space line heights are: 469 | - never negative, 470 | - only positive when `window-start' equals 1, 471 | `topspace-active' returns non-nil, and `topspace-mode' is enabled, 472 | - not larger than `window-text-height' minus `topspace--context-lines'." 473 | (let ((max-height (- (window-text-height) topspace--context-lines))) 474 | (setq height (float height)) 475 | (when (> (window-start) 1) (setq height 0.0)) 476 | (when (< height 0) (setq height 0.0)) 477 | (when (> height max-height) (setq height max-height)) 478 | (unless (topspace--enabled) (setq height 0.0))) 479 | height) 480 | 481 | (defun topspace--window-end () 482 | "Return the up-to-date `window-end'." 483 | (or (window-end (selected-window) t))) 484 | 485 | (defun topspace--total-lines-past-max (&optional topspace-height) 486 | "Used when making sure top space height does not push cursor off-screen. 487 | Return how many lines past the bottom of the window the cursor would get pushed 488 | if setting the top space to the target value TOPSPACE-HEIGHT. 489 | Any value above 0 flags that the target TOPSPACE-HEIGHT is too large." 490 | (- (topspace--current-line-plus-topspace topspace-height) 491 | (- (window-text-height) topspace--context-lines))) 492 | 493 | (defun topspace--current-line-plus-topspace (&optional topspace-height) 494 | "Used when making sure top space height does not push cursor off-screen. 495 | Return the current line plus the top space height TOPSPACE-HEIGHT." 496 | (+ (topspace--count-lines (window-start) (point)) 497 | (or topspace-height (topspace-height)))) 498 | 499 | (defun topspace--calculate-recenter-line-offset (&optional line-offset) 500 | "Convert LINE-OFFSET to a line offset from the top of the window. 501 | It is interpreted in the same way as the first ARG in `recenter'." 502 | (unless line-offset (setq line-offset (/ (float (window-text-height)) 2))) 503 | (when (< line-offset 0) 504 | ;; subtracting 1 below made `recenter-top-bottom' act correctly 505 | ;; when it moves point to bottom and top space is added to get there 506 | (setq line-offset (- (- (window-text-height) line-offset) 507 | topspace--context-lines 508 | 1))) 509 | line-offset) 510 | 511 | (defun topspace--center-line (&optional position) 512 | "Calculate the centering position when using `topspace-recenter-buffer'. 513 | Return how many lines away from the top of the selected window that the 514 | buffer's center line will be moved to based on POSITION, which defaults to 515 | `topspace-center-position'. Note that when POSITION 516 | is a floating-point number, the return value is only valid for windows 517 | starting at the top of the frame, which must be accounted for in the calling 518 | functions." 519 | (setq position (or position (topspace--eval-choice topspace-center-position))) 520 | (if (floatp position) 521 | (* (topspace--frame-height) position) 522 | (topspace--calculate-recenter-line-offset position))) 523 | 524 | (defun topspace--height-to-recenter-buffer (&optional position) 525 | "Return the necessary top space height to center selected window's buffer. 526 | Buffer will be centered according to POSITION, which defaults to 527 | `topspace-center-position'." 528 | (setq position (or position (topspace--eval-choice topspace-center-position))) 529 | (let ((buffer-height (topspace--count-lines 530 | (window-start) 531 | (topspace--window-end))) 532 | (result) 533 | (window-height (window-text-height))) 534 | (setq result (- (topspace--center-line position) (/ buffer-height 2))) 535 | (when (floatp position) (setq result (- result (window-top-line)))) 536 | (when (> (+ result buffer-height) 537 | (- window-height topspace--context-lines)) 538 | (setq result (- (- window-height buffer-height) 539 | topspace--context-lines))) 540 | result)) 541 | 542 | (defun topspace--frame-height () 543 | "Return the number of lines in the selected frame's text area. 544 | Subtract 3 from `frame-text-lines' to discount echo area and bottom 545 | mode-line in centering." 546 | (- (frame-text-lines) 3)) 547 | 548 | (defun topspace--count-pixel-height (start end) 549 | "Return total pixels between points START and END as if they're both visible." 550 | (let ((result 0)) 551 | (save-excursion 552 | (goto-char end) 553 | (beginning-of-visual-line) 554 | (setq end (point)) 555 | (goto-char start) 556 | (beginning-of-visual-line) 557 | (while (< (point) end) 558 | (setq result (+ result (line-pixel-height))) 559 | (vertical-motion 1))) 560 | result)) 561 | 562 | (defun topspace--count-lines-slow (start end) 563 | "Return screen lines between points START and END. 564 | Like `topspace--count-lines' but is a slower backup alternative." 565 | (/ (topspace--count-pixel-height start end) (float (default-line-height)))) 566 | 567 | (defun topspace--count-lines (start end) 568 | "Return screen lines between points START and END. 569 | Like `count-screen-lines' except `count-screen-lines' will 570 | return unexpected value when END is in column 0. This fixes that issue. 571 | This function also tries to first count the lines using a potentially faster 572 | technique involving `window-absolute-pixel-position'. 573 | If that doesn't work it uses `topspace--count-lines-slow'." 574 | (let ((old-end) (old-start) (swap) 575 | (line-height (float (default-line-height)))) 576 | (when (> start end) (setq swap end) (setq end start) (setq start swap)) 577 | (setq old-end end) (setq old-start start) 578 | ;; use faster visual method for counting portion of lines in screen: 579 | (when (< start (topspace--window-end)) 580 | (setq end (min end (topspace--window-end)))) 581 | (when (> end (window-start)) 582 | (setq start (max start (window-start)))) 583 | (let ((end-y (window-absolute-pixel-position end)) 584 | (start-y (window-absolute-pixel-position start))) 585 | (+ 586 | (if (> old-end end) (topspace--count-lines-slow end old-end) 0.0) 587 | (if (< old-start start) (topspace--count-lines-slow old-start start) 0.0) 588 | (condition-case nil 589 | ;; first try counting lines by getting the pixel difference 590 | ;; between end and start and dividing by `default-line-height' 591 | (/ (- (cdr end-y) (cdr start-y)) line-height) 592 | ;; if the pixel method above doesn't work do this slower method 593 | ;; (it won't work if either START or END are not visible in window) 594 | (error (topspace--count-lines-slow start end))))))) 595 | 596 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 597 | ;;; Overlay drawing 598 | 599 | (defun topspace--text (height) 600 | "Return the topspace text that appears in the top overlay with height HEIGHT." 601 | (cond 602 | ((= (round height) 0) "") 603 | ((= (round height) 1) 604 | ;; comment a) You cannot set a string's line-height 605 | ;; to a positive float less than 1. So in this condition, 606 | ;; settle for rounding the top space height up to 1 607 | "\n") 608 | (t 609 | ;; set the text to a series of newline characters with the last line 610 | ;; having a line-height set to a float accounting for the potential 611 | ;; fractional portion of the top space height 612 | (let ((text "") 613 | (indicator-line (topspace--eval-choice 614 | topspace-empty-line-indicator))) 615 | (setq indicator-line (cl-concatenate 'string indicator-line "\n")) 616 | (dotimes (n (1- (floor height))) 617 | n ;; remove flycheck warning 618 | (setq text (cl-concatenate 'string text indicator-line))) 619 | (setq indicator-line 620 | ;; set that last line with a float line-height. 621 | ;; The float will be set to >1 due to comment a) above 622 | (propertize indicator-line 'line-height 623 | (- (1+ height) (floor height)))) 624 | (cl-concatenate 'string text indicator-line))))) 625 | 626 | (defun topspace--increase-height (total-lines) 627 | "Increase the top space line height by the target amount of TOTAL-LINES." 628 | (topspace-set-height (+ (topspace-height) total-lines))) 629 | 630 | (defun topspace--decrease-height (total-lines) 631 | "Decrease the top space line height by the target amount of TOTAL-LINES." 632 | (topspace-set-height (- (topspace-height) total-lines))) 633 | 634 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 635 | ;;; Utilities 636 | 637 | (defun topspace--eval-choice (variable-or-function) 638 | "Evaluate VARIABLE-OR-FUNCTION which is either var or func'n of type var. 639 | If it is a variable, return its value, if it is a function, 640 | evaluate the function and return its return value. 641 | VARIABLE-OR-FUNCTION is most likely a user customizable variable of choice 642 | type." 643 | (condition-case nil 644 | (funcall variable-or-function) 645 | (error variable-or-function))) 646 | 647 | (defun topspace--previous-line (&optional arg try-vscroll) 648 | "Functionally identical to `previous-line' but for non-interactive use. 649 | Use TRY-VSCROLL to control whether to vscroll tall 650 | lines: if either `auto-window-vscroll' or TRY-VSCROLL is nil, this 651 | function will not vscroll. 652 | ARG defaults to 1." 653 | (or arg (setq arg 1)) 654 | (line-move (- arg) nil nil try-vscroll) 655 | nil) 656 | 657 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 658 | ;;; Hooks 659 | 660 | (defun topspace--window-configuration-change () 661 | "Update top spaces when window buffers change or windows are resized." 662 | (setq topspace--got-first-window-configuration-change t) 663 | (let ((current-height (window-text-height)) (window (selected-window))) 664 | (let ((previous-height (alist-get window topspace--previous-window-heights 665 | 0.0))) 666 | (if (and (topspace--eval-choice topspace-autocenter-buffers) 667 | (not (= previous-height current-height))) 668 | (topspace-recenter-buffer) 669 | (topspace-set-height)) 670 | (setf (alist-get window topspace--previous-window-heights) 671 | current-height)))) 672 | 673 | (defun topspace--pre-command () 674 | "Reduce the amount of code that must execute in `topspace--post-command'." 675 | (setq-local topspace--pre-command-point (point)) 676 | (setq-local topspace--pre-command-window-start (window-start))) 677 | 678 | (defun topspace--post-command () 679 | "Reduce top space height before the cursor can move past `window-end'." 680 | (when (and (= topspace--pre-command-window-start 1) 681 | (> (point) topspace--pre-command-point)) 682 | (let ((next-line-point)) 683 | (save-excursion 684 | (goto-char topspace--pre-command-point) 685 | (vertical-motion 1) 686 | (beginning-of-visual-line) 687 | (setq next-line-point (point))) 688 | (when (and 689 | ;; These checks are for improving performance by only running 690 | ;; `topspace--count-lines' run by `topspace--total-lines-past-max' 691 | ;; when necessary because `topspace--count-lines' is slow 692 | (>= (point) next-line-point) 693 | (< (- (line-number-at-pos (point)) 694 | (line-number-at-pos topspace--pre-command-point)) 695 | (window-text-height))) 696 | (let ((topspace-height (topspace-height)) (total-lines-past-max)) 697 | (when (> topspace-height 0) 698 | (setq total-lines-past-max (topspace--total-lines-past-max 699 | topspace-height)) 700 | (when (> total-lines-past-max 0) 701 | (topspace--decrease-height total-lines-past-max))))))) 702 | (when (and (= (window-start) 1) 703 | topspace--got-first-window-configuration-change) 704 | (topspace-set-height))) 705 | 706 | (defvar topspace--hook-alist 707 | '((window-configuration-change-hook . topspace--window-configuration-change) 708 | (pre-command-hook . topspace--pre-command) 709 | (post-command-hook . topspace--post-command)) 710 | "A list of hooks to add/remove in the format (hook-variable . function).") 711 | 712 | (defun topspace--add-hooks () 713 | "Add hooks defined in `topspace--hook-alist'." 714 | (dolist (hook-func-pair topspace--hook-alist) 715 | (add-hook (car hook-func-pair) (cdr hook-func-pair) -90 t))) 716 | 717 | (defun topspace--remove-hooks () 718 | "Remove hooks defined in `topspace--hook-alist'." 719 | (dolist (hook-func-pair topspace--hook-alist) 720 | (remove-hook (car hook-func-pair) (cdr hook-func-pair) t))) 721 | 722 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 723 | ;;; Mode definition and setup 724 | 725 | (defun topspace--enable-p () 726 | "Return non-nil if buffer is allowed to enable `topspace-mode.'. 727 | Topspace will not be enabled for: 728 | - minibuffers 729 | - ephemeral buffers (See Info node `(elisp)Buffer Names') 730 | - if `topspace-mode' is already enabled" 731 | (not (or (minibufferp) (string-prefix-p " " (buffer-name))))) 732 | 733 | (defun topspace--enable () 734 | "Enable `topspace-mode' and do mode setup." 735 | (when (topspace--enable-p) 736 | (topspace--add-hooks) 737 | (unless topspace--advice-added 738 | (setq topspace--advice-added t) 739 | (advice-add #'scroll-up :filter-args #'topspace--filter-args-scroll-up) 740 | (advice-add #'scroll-down :filter-args 741 | #'topspace--filter-args-scroll-down) 742 | (advice-add #'scroll-up :after #'topspace--after-scroll) 743 | (advice-add #'scroll-down :after #'topspace--after-scroll) 744 | (advice-add #'recenter :after #'topspace--after-recenter) 745 | (when (fboundp 'smooth-scroll-lines-above-point) 746 | (advice-add #'smooth-scroll-lines-above-point 747 | :override #'topspace--smooth-scroll-lines-above-point))) 748 | (dolist (window (get-buffer-window-list)) 749 | (with-selected-window window (topspace-set-height))))) 750 | 751 | (defun topspace--disable () 752 | "Disable `topspace-mode' and do mode cleanup." 753 | (remove-overlays 1 1 'topspace--remove-from-buffer-tag t) 754 | (topspace--remove-hooks)) 755 | 756 | ;;;###autoload 757 | (define-minor-mode topspace-mode 758 | "Recenter line 1 with scrollable upper margin/padding. 759 | 760 | TopSpace lets you display a buffer's first line in the center of a window 761 | instead of just at the top. 762 | This is done by automatically drawing an upper margin/padding above line 1 763 | as you recenter and scroll it down. 764 | 765 | See https://github.com/trevorpogue/topspace for a GIF demo & documentation. 766 | 767 | Features: 768 | 769 | - Easier on the eyes: Recenter or scroll down top text to a more 770 | comfortable eye level for reading, especially when in full-screen 771 | or on a large monitor. 772 | 773 | - Easy to use: No new keybindings are required, keep using all 774 | your previous scrolling & recentering commands, except now you 775 | can also scroll above the top lines. It also integrates 776 | seamlessly with `centered-cursor-mode' to keep the cursor 777 | centered all the way to the top line. 778 | 779 | Enabling/disabling: 780 | When called interactively, toggle `topspace-mode'. 781 | 782 | With prefix ARG, enable `topspace-mode' if 783 | ARG is positive, otherwise disable it. 784 | 785 | When called from Lisp, enable `topspace-mode' if 786 | ARG is omitted, nil or positive. 787 | 788 | If ARG is `toggle', toggle `topspace-mode'. 789 | Otherwise behave as if called interactively." 790 | :init-value nil 791 | :ligher topspace-mode-line 792 | :keymap topspace-keymap 793 | :group 'topspace 794 | (if topspace-mode (topspace--enable) (topspace--disable))) 795 | 796 | ;;;###autoload 797 | (define-globalized-minor-mode global-topspace-mode topspace-mode 798 | topspace-mode 799 | :group 'topspace) 800 | 801 | (defun topspace--enabled () 802 | "Return t only if both `topspace-mode' and `topspace-active' are non-nil." 803 | (and (topspace--eval-choice topspace-active) topspace-mode)) 804 | 805 | (provide 'topspace) 806 | 807 | ;;; topspace.el ends here 808 | --------------------------------------------------------------------------------