emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/osm f2fba2ebdf 43/77: Auto rename the buffers


From: ELPA Syncer
Subject: [elpa] externals/osm f2fba2ebdf 43/77: Auto rename the buffers
Date: Mon, 7 Mar 2022 08:58:06 -0500 (EST)

branch: externals/osm
commit f2fba2ebdf6b00031400658baf610e6ad877f2ea
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>

    Auto rename the buffers
---
 README.org |   5 ---
 osm-ol.el  |   8 ++--
 osm.el     | 138 +++++++++++++++++++++++--------------------------------------
 3 files changed, 56 insertions(+), 95 deletions(-)

diff --git a/README.org b/README.org
index 0454772f0b..df02910ef6 100644
--- a/README.org
+++ b/README.org
@@ -37,10 +37,6 @@ Examples:
 - [[osm:stamen-watercolor:40.72956780913898,-73.97918701171875,12][New York, 
United States, 40.73° -73.98° Stamen Watercolor]]
 - [[osm:opentopomap:27.961656050984658,86.89224243164062,13][Mount Everest, 
27.96° 86.89° OpenTopoMap]]
 
-In order to retrieve a meaningful name for the current location press ~n~ in 
the
-~org-mode~ buffer first. Then the buffer is renamed. The links and bookmarks 
will
-reuse the buffer name for their description.
-
 * Commands and Key Bindings
 
 Top-level commands:
@@ -57,7 +53,6 @@ Key bindings in =osm-mode= buffer:
 - ~h~: =osm-home=
 - ~s~: =osm-search=
 - ~S~: =osm-server=
-- ~n~: =osm-rename=
 - ~b~: =bookmark-set=
 - ~B~: =bookmark-jump=
 - ~q~: =quit-window=
diff --git a/osm-ol.el b/osm-ol.el
index b4ae528155..b18b4aed0e 100644
--- a/osm-ol.el
+++ b/osm-ol.el
@@ -42,10 +42,10 @@
              link)
       (error "Invalid osm link"))
     (osm--setup
-     :at (list (string-to-number (match-string 2 link))
-               (string-to-number (match-string 3 link))
-               (string-to-number (match-string 4 link)))
-     :server (and (match-end 1) (intern (match-string 1 link))))))
+     (list (string-to-number (match-string 2 link))
+           (string-to-number (match-string 3 link))
+           (string-to-number (match-string 4 link)))
+     (and (match-end 1) (intern (match-string 1 link))))))
 
 (defun osm-ol-store ()
   "Store osm link."
diff --git a/osm.el b/osm.el
index 02bbce9c10..4a689de25c 100644
--- a/osm.el
+++ b/osm.el
@@ -45,12 +45,12 @@
      :min-zoom 2 :max-zoom 19 :max-connections 2
      :url "https://[abc].tile.openstreetmap.org/%z/%x/%y.png";)
     (de
-     :name "Mapnik (de)"
+     :name "Mapnik:de"
      :description "Localized Mapnik map provided by OpenStreetMap Deutschland"
      :min-zoom 2 :max-zoom 19 :max-connections 2
      :url "https://[abc].tile.openstreetmap.de/%z/%x/%y.png";)
     (fr
-     :name "Mapnik (fr)"
+     :name "Mapnik:fr"
      :description "Localized Mapnik map by OpenStreetMap France"
      :min-zoom 2 :max-zoom 19 :max-connections 2
      :url "https://[abc].tile.openstreetmap.fr/osmfr/%z/%x/%y.png";)
@@ -144,7 +144,6 @@ Should be at least 7 days according to the server usage 
policies."
     (define-key map "S" #'osm-server)
     (define-key map "b" #'bookmark-set)
     (define-key map "B" #'bookmark-jump)
-    (define-key map "n" #'osm-rename)
     (define-key map [remap scroll-down-command] #'osm-down)
     (define-key map [remap scroll-up-command] #'osm-up)
     (define-key map "\d" nil)
@@ -489,7 +488,7 @@ We need two distinct images which are not `eq' for the 
display properties.")
 (defun osm-home ()
   "Go to home coordinates."
   (interactive)
-  (osm--setup :at (osm--home-coordinates)))
+  (osm--setup (osm--home-coordinates) nil))
 
 (defun osm--queue-info ()
   "Return queue info string."
@@ -506,6 +505,7 @@ We need two distinct images which are not `eq' for the 
display properties.")
   "Update map display."
   (unless (eq major-mode #'osm-mode)
     (error "Not an osm-mode buffer"))
+  (rename-buffer (osm--buffer-name) 'unique)
   (with-silent-modifications
     (let* ((meter-per-pixel (/ (* 156543.03 (cos (/ (osm--lat) (/ 180.0 
float-pi)))) (expt 2 osm--zoom)))
            (meter '(1 5 10 50 100 500 1000 5000 10000 50000 100000 500000 
1000000 5000000 10000000))
@@ -523,8 +523,7 @@ We need two distinct images which are not `eq' for the 
display properties.")
       (setq-local
        header-line-format
        (list
-        (format " %s %s %s    Z%-2d    %s%s%s %s %s    "
-                (osm--server-property :name)
+        (format "%s %s    Z%-2d    %s%s%s %s %s    "
                 (format #("%7.2f°" 0 5 (face bold)) (osm--lat))
                 (format #("%7.2f°" 0 5 (face bold)) (osm--lon))
                 osm--zoom
@@ -536,7 +535,11 @@ We need two distinct images which are not `eq' for the 
display properties.")
                             'display '(space :width (3)))
                 (if (>= meter 1000) (/ meter 1000) meter)
                 (if (>= meter 1000) "km" "m"))
-        '(:eval (osm--queue-info))))
+        '(:eval (osm--queue-info))
+        (let ((server (osm--server-property :name)))
+          (concat
+           (propertize " " 'display `(space :align-to (- right ,(length 
server) 2)))
+           server))))
       (erase-buffer)
       (dotimes (_j osm--ny)
         (insert (make-string osm--nx ?\s) "\n"))
@@ -568,13 +571,9 @@ We need two distinct images which are not `eq' for the 
display properties.")
 
 (defun osm--bookmark-name ()
   "Return default bookmark name."
-  (if (osm--generated-name-p)
-      (format "osm: %.2f° %.2f° %s"
-              (osm--lat) (osm--lon)
-              (osm--server-property :name))
-    (replace-regexp-in-string
-     "\\`\\*\\|\\*\\(?:<[0-9]+>\\)?\\'"
-     "" (buffer-name))))
+  (replace-regexp-in-string
+   "\\`\\*\\|\\*\\(?:<[0-9]+>\\)?\\'"
+   "" (buffer-name)))
 
 (defun osm--link-data ()
   "Return link data."
@@ -585,62 +584,46 @@ We need two distinct images which are not `eq' for the 
display properties.")
               (string-remove-suffix (concat " " (osm--server-property :name)) 
name)
             name))))
 
-(defun osm--default-buffer-name ()
-  "Return default buffer name."
-  (format "*osm: %s*" (osm--server-property :name)))
+(defun osm--buffer-name ()
+  "Return buffer name."
+  (format "*osm: %.2f° %.2f° Z%s %s*"
+          (osm--lat) (osm--lon) osm--zoom
+          (osm--server-property :name)))
 
-(defun osm--generated-name-p ()
-  "Return non-nil if the buffer has a generated name."
-  (string-match-p
-   (format "\\`\\*osm:\\(?: [0-9.-]+° [0-9.-]+°\\)? %s\\*\\(?:<[0-9]+>\\)?\\'"
-           (regexp-quote (osm--server-property :name)))
-   (buffer-name)))
-
-(cl-defun osm--setup (&key at server name)
-  "Setup buffer NAME with SERVER at coordinates AT."
+(defun osm--setup (at server)
+  "Setup buffer with SERVER at coordinates AT."
   ;; Server not found
   (when (and server (not (assq server osm-server-list))) (setq server nil))
   (with-current-buffer
-      (if (eq major-mode #'osm-mode)
-          (current-buffer)
-        (pcase-let* ((def-name (or name
-                                   (let ((osm-server (or server osm-server)))
-                                     (osm--default-buffer-name))))
-                     (`(,def-lat ,def-lon ,def-zoom) (or at 
(osm--home-coordinates)))
-                     (def-x (osm--lon-to-x def-lon def-zoom))
-                     (def-y (osm--lat-to-y def-lat def-zoom))
-                     (def-server (or server osm-server))
-                     (def-name-regexp (format "\\`%s\\(?:<[0-9]+>\\)?\\'"
-                                              (regexp-quote def-name))))
-          (or (cl-loop
-               ;; Search for existing buffer
-               for buf in (buffer-list) thereis
-               (and (eq (buffer-local-value 'major-mode buf) #'osm-mode)
-                    (eq (buffer-local-value 'osm-server buf) def-server)
-                    (eq (buffer-local-value 'osm--zoom buf) def-zoom)
-                    (eq (buffer-local-value 'osm--x buf) def-x)
-                    (eq (buffer-local-value 'osm--y buf) def-y)
-                    (string-match-p def-name-regexp (buffer-name buf))
-                    buf))
-              (generate-new-buffer def-name))))
-    (let ((auto-rename (or name (osm--generated-name-p))))
-      (unless (eq major-mode #'osm-mode)
-        (osm-mode))
-      (when (and server (not (eq osm-server server)))
-        (setq osm-server server
-              osm--active nil
-              osm--queue nil))
-      (when auto-rename
-        (setq name (or name (osm--default-buffer-name)))
-        (unless (equal name (buffer-name))
-          (rename-buffer name 'unique)))
-      (when (or (not (and osm--x osm--y)) at)
-        (setq at (or at (osm--home-coordinates))
-              osm--zoom (nth 2 at)
-              osm--x (osm--lon-to-x (nth 1 at) osm--zoom)
-              osm--y (osm--lat-to-y (nth 0 at) osm--zoom)))
-      (prog1 (pop-to-buffer (current-buffer))
-        (osm--update)))))
+      (or
+       (and (eq major-mode #'osm-mode) (current-buffer))
+       (pcase-let* ((`(,def-lat ,def-lon ,def-zoom) (or at 
(osm--home-coordinates)))
+                    (def-x (osm--lon-to-x def-lon def-zoom))
+                    (def-y (osm--lat-to-y def-lat def-zoom))
+                    (def-server (or server osm-server)))
+         ;; Search for existing buffer
+         (cl-loop
+          for buf in (buffer-list) thereis
+          (and (eq (buffer-local-value 'major-mode buf) #'osm-mode)
+               (eq (buffer-local-value 'osm-server buf) def-server)
+               (eq (buffer-local-value 'osm--zoom buf) def-zoom)
+               (eq (buffer-local-value 'osm--x buf) def-x)
+               (eq (buffer-local-value 'osm--y buf) def-y)
+               buf)))
+       (generate-new-buffer "*osm*"))
+    (unless (eq major-mode #'osm-mode)
+      (osm-mode))
+    (when (and server (not (eq osm-server server)))
+      (setq osm-server server
+            osm--active nil
+            osm--queue nil))
+    (when (or (not (and osm--x osm--y)) at)
+      (setq at (or at (osm--home-coordinates))
+            osm--zoom (nth 2 at)
+            osm--x (osm--lon-to-x (nth 1 at) osm--zoom)
+            osm--y (osm--lat-to-y (nth 0 at) osm--zoom)))
+    (prog1 (pop-to-buffer (current-buffer))
+      (osm--update))))
 
 ;;;###autoload
 (defun osm-goto (lat lon zoom)
@@ -653,19 +636,13 @@ We need two distinct images which are not `eq' for the 
display properties.")
      (unless (and (numberp lat) (numberp lon) (numberp zoom))
        (error "Invalid coordinate"))
      (list lat lon zoom)))
-  (osm--setup :at (list lat lon zoom)))
+  (osm--setup (list lat lon zoom) nil))
 
 ;;;###autoload
 (defun osm-bookmark-jump (bm)
   "Jump to OSM bookmark BM."
   (set-buffer
-   (osm--setup
-    :at (alist-get 'coordinate bm)
-    :server (alist-get 'server bm)
-    :name
-    (if (string-match-p "\\`\\*.*\\*\\'" (car bm))
-        (car bm)
-      (format "*%s*" (car bm))))))
+   (osm--setup (alist-get 'coordinate bm) (alist-get 'server bm))))
 
 (defun osm--location-name ()
   "Return descriptive string for current map."
@@ -685,17 +662,6 @@ We need two distinct images which are not `eq' for the 
display properties.")
     (message "%s" (or name "No name found"))
     name))
 
-;;;###autoload
-(defun osm-rename ()
-  "Rename buffer, use name of current location."
-  (interactive)
-  (when-let (desc (osm--location-name))
-    (rename-buffer
-     (format "*osm: %s, %.2f° %.2f° %s*"
-             desc (osm--lat) (osm--lon)
-             (osm--server-property :name))
-     'unique)))
-
 ;;;###autoload
 (defun osm-search ()
   "Search for location and display the map."
@@ -752,7 +718,7 @@ We need two distinct images which are not `eq' for the 
display properties.")
                              (or (osm--server-property :description) "")))))
      (list (or (cdr (assoc selected servers))
                (error "No server selected")))))
-  (osm--setup :server server))
+  (osm--setup nil server))
 
 (dolist (sym (list #'osm-up #'osm-down #'osm-left #'osm-right
                    #'osm-up-large #'osm-down-large #'osm-left-large 
#'osm-right-large



reply via email to

[Prev in Thread] Current Thread [Next in Thread]