From 7418e41181a9fb829365b4050b51575e1f773881 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Wed, 25 Feb 2026 18:18:06 +0100 Subject: m + add "before" function for collation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- LICENSE | 2 +- Makefile | 1 + README | 12 ++++++++++-- dlu.1 | 15 +++++++++++++-- dlu.py | 5 +++-- 5 files changed, 28 insertions(+), 7 deletions(-) diff --git a/LICENSE b/LICENSE index 94f605f..29d6e2d 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ ISC License -© 2016 Mattias Andrée +© 2016, 2026 Mattias Andrée Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/Makefile b/Makefile index 177852e..e9bf4c7 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,7 @@ COMMAND = dlu PKGNAME = dlu all: + @: install: install-base install-doc install-base: install-cmd install-copyright diff --git a/README b/README index a6a989c..d4bf65d 100644 --- a/README +++ b/README @@ -30,10 +30,18 @@ DESCRIPTION Modifies and returns a word so that it can be used to compare against known words in the dictionary. - The default implementation of this function converts the - word to lower case using Python's string class's + The default implementation of this function converts + the word to lower case using Python's string class's lower() function. + before(word1 : str, word2 : str) -> bool + Collation function that checks that word1 comes before + word2 in the dictionary (if so, it returns True, + otherwise it returns False). + + The default implementation of this function compares + in C locale. + get() -> tuple Returns a 3-tuple containing, in order: the filename of the scanned dictionary, a list of the last word on diff --git a/dlu.1 b/dlu.1 index ab4d5bd..9e94d26 100644 --- a/dlu.1 +++ b/dlu.1 @@ -61,6 +61,19 @@ to lower case using Python's string class's .BR lower () function. .TP +.BR before "(\fIword1\fP : str, \fIword2\fP : str) -> bool" +Collation function that checks that +.I word1 +comes before +.I word2 +in the dictionary (if so, it returns +.BR True , +otherwise it returns +.BR False ). + +The default implementation of this function compares +in C locale. +.TP .BR get "() -> tuple" Returns a 3-tuple containing, in order: the filename of the scanned dictionary, a list of the last word on @@ -75,5 +88,3 @@ Print a list of all dictionaries. .TP .B ~/.config/dlu/dlurc The configuration file. -.SH BUGS -Please report bugs to m@maandree.se diff --git a/dlu.py b/dlu.py index 3711a66..edaf0fc 100755 --- a/dlu.py +++ b/dlu.py @@ -2,7 +2,7 @@ import sys, os -global dictionary_name, sought_word, display_envs, x_reads, reads, wordmod, standard_page_remap, load_dictionary, open_dictionary +global dictionary_name, sought_word, display_envs, x_reads, reads, wordmod, standard_page_remap, load_dictionary, open_dictionary, before ## Parse command line. def usage(): @@ -43,6 +43,7 @@ if not f_list: reads = dict((disp, list(x_reads)) for disp in display_envs) reads[None] = [lambda f, p : ['jfbview', '-p', p, '--', f]] wordmod = lambda x : x.lower() + before = lambda a, b: a < b def standard_page_remap(offset, multiple = 1, multiple_offset = 0): return lambda p : (0 if p < multiple_offset else p - multiple_offset) // multiple + offset def open_dictionary(filename, page): @@ -132,7 +133,7 @@ lasts = [(i, word) for i, word in enumerate(lasts)] for i, word in lasts: word = wordmod(word) - if sought_word <= word: + if not before(word, sought_word): page = i break else: -- cgit v1.2.3-70-g09d2